name.go 555 B

12345678910111213141516171819202122232425
  1. package web
  2. import "strings"
  3. const encodedIDPrefix = ":"
  4. // Parse the shortcut name from the given URL path, given the base URL that is
  5. // handling the request.
  6. func parseName(base, path string) string {
  7. t := path[len(base):]
  8. ix := strings.Index(t, "/")
  9. if ix == -1 {
  10. return t
  11. }
  12. return t[:ix]
  13. }
  14. // Clean a shortcut name. Currently this just means stripping any leading
  15. // ":" to avoid collisions with auto generated names.
  16. func cleanName(name string) string {
  17. for strings.HasPrefix(name, encodedIDPrefix) {
  18. name = name[1:]
  19. }
  20. return name
  21. }