Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidULIDLen = errors.New("invalid length of ULID")
View Source
var ErrOverflow = errors.New("overflow random value")
ErrOverflow represents error when overflow random value
Functions ¶
Types ¶
type ULID ¶
type ULID struct {
// contains filtered or unexported fields
}
ULID represents ULID
func New ¶
New generates new ULID
Example ¶
package main import ( "fmt" "time" "github.com/matsuyoshi30/ulidgo" ) var Now = func() time.Time { return time.Date(2022, time.April, 7, 1, 2, 30, 45, time.UTC) } func main() { ulid, _ := ulidgo.New(Now().UnixMilli()) fmt.Println(ulid) }
Output: 01G00RPN3GNQDPDEA8MJAJS8SJ
Example (Multi) ¶
package main import ( "fmt" "time" "github.com/matsuyoshi30/ulidgo" ) func main() { nt := time.Date(2022, time.April, 8, 1, 2, 30, 45, time.UTC) ulid1, _ := ulidgo.New(nt.UnixMilli()) ulid2, _ := ulidgo.New(nt.UnixMilli()) ulid3, _ := ulidgo.New(nt.UnixMilli()) fmt.Printf("%s\n%s\n%s\n", ulid1, ulid2, ulid3) }
Output: 01G03B3C3GCZVQY8TYZAEPCGQ5 01G03B3C3GCZVQY8TYZAEPCGQ6 01G03B3C3GCZVQY8TYZAEPCGQ7
func (*ULID) Compare ¶
Compare returns an integer comparing two ULID byte slice The result will be 0 if u == target, -1 if u < target and +1 if u > target
func (*ULID) Time ¶
Time returns UTC converted from ULID unix timestamp value
Example ¶
package main import ( "fmt" "time" "github.com/matsuyoshi30/ulidgo" ) var Now = func() time.Time { return time.Date(2022, time.April, 7, 1, 2, 30, 45, time.UTC) } func main() { ulid, _ := ulidgo.New(Now().UnixMilli()) fmt.Println(ulid.Time()) }
Output: 2022-04-07 01:02:30 +0000 UTC
Click to show internal directories.
Click to hide internal directories.