names.go 637 B

12345678910111213141516171819202122232425
  1. package protocol
  2. import (
  3. "regexp"
  4. )
  5. // var validTopicChannelNameRegex = regexp.MustCompile(`^[\.a-zA-Z0-9_-]+(#ephemeral)?$`)
  6. var validTopicChannelNameRegex = regexp.MustCompile("^[\u4e00-\u9fa5a-zA-Z0-9_-]+(#ephemeral)?$")
  7. // IsValidTopicName checks a topic name for correctness
  8. func IsValidTopicName(name string) bool {
  9. return isValidName(name)
  10. }
  11. // IsValidChannelName checks a channel name for correctness
  12. func IsValidChannelName(name string) bool {
  13. return isValidName(name)
  14. }
  15. func isValidName(name string) bool {
  16. if len(name) > 64 || len(name) < 1 {
  17. return false
  18. }
  19. return validTopicChannelNameRegex.MatchString(name)
  20. }