/internal/service/types/id.go
Go | 24 lines | 13 code | 6 blank | 5 comment | 2 complexity | b2729f5797798dd3398fa2745d78aa48 MD5 | raw file
Possible License(s): BSD-2-Clause, MIT, JSON, BSD-3-Clause, 0BSD, Apache-2.0, MPL-2.0-no-copyleft-exception
- package types
- import "regexp"
- // [4] means that supported only v4.
- 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}$)`)
- // ID wraps built-in `string` type and provides useful methods above it.
- type ID string
- // IsEmpty returns true if the ID is empty.
- func (id ID) IsEmpty() bool {
- return id == ""
- }
- // IsValid returns true if the ID is not empty and compatible with RFC 4122.
- func (id ID) IsValid() bool {
- return !id.IsEmpty() && uuid.MatchString(string(id))
- }
- // String implements built-in `fmt.Stringer` interface and returns the underlying string value.
- func (id ID) String() string {
- return string(id)
- }