topic_channel_args.go 659 B

123456789101112131415161718192021222324252627282930313233
  1. package http_api
  2. import (
  3. "errors"
  4. "github.com/nsqio/nsq/internal/protocol"
  5. )
  6. type getter interface {
  7. Get(key string) (string, error)
  8. }
  9. func GetTopicChannelArgs(rp getter) (string, string, error) {
  10. topicName, err := rp.Get("topic")
  11. if err != nil {
  12. return "", "", errors.New("MISSING_ARG_TOPIC")
  13. }
  14. if !protocol.IsValidTopicName(topicName) {
  15. return "", "", errors.New("INVALID_ARG_TOPIC")
  16. }
  17. channelName, err := rp.Get("channel")
  18. if err != nil {
  19. return "", "", errors.New("MISSING_ARG_CHANNEL")
  20. }
  21. if !protocol.IsValidChannelName(channelName) {
  22. return "", "", errors.New("INVALID_ARG_CHANNEL")
  23. }
  24. return topicName, channelName, nil
  25. }