PageRenderTime 51ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/internal/domain/uuid.go

https://bitbucket.org/kamilsk/passport
Go | 24 lines | 13 code | 6 blank | 5 comment | 3 complexity | b0a11aace52c7b7f056db8cc72ae03a5 MD5 | raw file
Possible License(s): BSD-2-Clause, MIT, JSON, 0BSD, BSD-3-Clause, Apache-2.0, MPL-2.0-no-copyleft-exception
  1. package domain
  2. import "regexp"
  3. // [4] means that supported only v4.
  4. var uuid = regexp.MustCompile(`(?i:^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$)`)
  5. // UUID wraps built-in `string` type and provides useful methods above it.
  6. type UUID string
  7. // IsEmpty returns true if the UUID has empty value.
  8. func (s UUID) IsEmpty() bool {
  9. return s == ""
  10. }
  11. // IsValid returns true if the UUID is compatible with RFC 4122.
  12. func (s UUID) IsValid() bool {
  13. return !(s == "") && uuid.MatchString(string(s)) // IsEmpty and String were inlined manually
  14. }
  15. // String implements built-in `fmt.Stringer` interface and returns string representation of the UUID.
  16. func (s UUID) String() string {
  17. return string(s)
  18. }