github.com/octohelm/storage@v0.0.0-20240516030302-1ac2cc1ea347/pkg/datatypes/sfid.go (about) 1 package datatypes 2 3 import "strconv" 4 5 // openapi:strfmt snowflake-id 6 type SFID uint64 7 8 func (sfID SFID) MarshalText() ([]byte, error) { 9 return []byte(sfID.String()), nil 10 } 11 12 func (sfID *SFID) UnmarshalText(data []byte) (err error) { 13 str := string(data) 14 if len(str) == 0 { 15 return 16 } 17 var u uint64 18 u, err = strconv.ParseUint(str, 10, 64) 19 *sfID = SFID(u) 20 return 21 } 22 23 func (sfID SFID) String() string { 24 return strconv.FormatUint(uint64(sfID), 10) 25 } 26 27 type SFIDs []SFID 28 29 func (uuids SFIDs) ToUint64() []uint64 { 30 var l []uint64 31 for _, id := range uuids { 32 l = append(l, uint64(id)) 33 } 34 return l 35 }