keywords.go 571 B

123456789101112131415161718192021222324252627282930313233
  1. package store
  2. import (
  3. "path"
  4. "strings"
  5. )
  6. // keywords for internal useage
  7. // Key for string keyword; Value for only checking prefix
  8. var keywords = map[string]bool{
  9. "/_etcd": true,
  10. "/ephemeralNodes": true,
  11. }
  12. // CheckKeyword will check if the key contains the keyword.
  13. // For now, we only check for prefix.
  14. func CheckKeyword(key string) bool {
  15. key = path.Clean("/" + key)
  16. // find the second "/"
  17. i := strings.Index(key[1:], "/")
  18. var prefix string
  19. if i == -1 {
  20. prefix = key
  21. } else {
  22. prefix = key[:i+1]
  23. }
  24. _, ok := keywords[prefix]
  25. return ok
  26. }