file.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package golang
  2. const fileTpl = `// Code generated by protoc-gen-validate. DO NOT EDIT.
  3. // source: {{ .InputPath }}
  4. package {{ pkg . }}
  5. import (
  6. "bytes"
  7. "errors"
  8. "fmt"
  9. "net"
  10. "net/mail"
  11. "net/url"
  12. "regexp"
  13. "strings"
  14. "time"
  15. "unicode/utf8"
  16. "google.golang.org/protobuf/types/known/anypb"
  17. {{ range $path, $pkg := enumPackages (externalEnums .) }}
  18. {{ $pkg }} "{{ $path }}"
  19. {{ end }}
  20. )
  21. // ensure the imports are used
  22. var (
  23. _ = bytes.MinRead
  24. _ = errors.New("")
  25. _ = fmt.Print
  26. _ = utf8.UTFMax
  27. _ = (*regexp.Regexp)(nil)
  28. _ = (*strings.Reader)(nil)
  29. _ = net.IPv4len
  30. _ = time.Duration(0)
  31. _ = (*url.URL)(nil)
  32. _ = (*mail.Address)(nil)
  33. _ = anypb.Any{}
  34. {{ range (externalEnums .) }}
  35. _ = {{ pkg . }}.{{ name . }}(0)
  36. {{ end }}
  37. )
  38. {{- if fileneeds . "uuid" }}
  39. // define the regex for a UUID once up-front
  40. var _{{ snakeCase .File.InputPath.BaseName }}_uuidPattern = regexp.MustCompile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
  41. {{ end }}
  42. {{ range .AllMessages }}
  43. {{ template "msg" . }}
  44. {{ end }}
  45. `