Skip to content

Commit

Permalink
Add interface description
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-fossati committed Sep 7, 2021
1 parent 2c0bbfe commit 880d265
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tagid.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type TagID struct {
val interface{}
}

// NewTagID takes a UUID (either as in string form or byte array) or an untyped
// string and returns a TagID
func NewTagID(v interface{}) *TagID {
switch t := v.(type) {
case string:
Expand All @@ -44,13 +46,15 @@ func string2TagID(s string) (*TagID, error) {
return nil, errors.New("tag-id is neither a UUID nor a valid string")
}

// NewTagIDFromString takes an untyped string and returns a TagID
func NewTagIDFromString(s string) (*TagID, error) {
if s == "" {
return nil, errors.New("empty string")
}
return &TagID{s}, nil
}

// NewTagIDFromUUIDString takes an UUID in string form and returns a TagID
func NewTagIDFromUUIDString(s string) (*TagID, error) {
u, err := uuid.Parse(s)
if err != nil {
Expand All @@ -60,6 +64,7 @@ func NewTagIDFromUUIDString(s string) (*TagID, error) {
return &TagID{u}, nil
}

// NewTagIDFromUUIDBytes takes an UUID as byte array and returns a TagID
func NewTagIDFromUUIDBytes(b []byte) (*TagID, error) {
u, err := uuid.FromBytes(b)
if err != nil {
Expand Down

0 comments on commit 880d265

Please sign in to comment.