Closed v1def closed 2 years ago
Ease of use, there are cases where you are sure that your ksuid is correct. But you need to get from bytes or string, example below.
func getPosts(before, after []byte) {
b, err := ksuid.FromBytes(before)
if err != nil {
panic(err)
}
a, err := ksuid.FromBytes(after)
if err != nil {
panic(err)
}
sortOptions := SortOptions{Before: b, After: a}
}
Instead, you can do it like this:
func getPosts(before, after []byte) {
sortOptions := SortOptions{
Before: ksuid.FromBytesOrNil(before),
After: ksuid.FromBytesOrNil(after),
}
}
KSUID already has something similar, ksuid.New()
, only this function panics on error. OrNil functions are also used in many other packages (uuid, ulid).
Thanks for sharing context!
Do you mind adding a section to the README with these examples to showcase how to use the new functions? Along with links to the other libraries you mentioned would be amazing as well!
Yes, thank you!
@achille-roussel Hello, sorry to disturb you. Maybe you didn't see this pull request?