# README
go.b8s.dev/primarykey
The goal with primarykey
is to provide a bridge between
github.com/google/uuid
and github.com/lithammer/shortuuid
while also
supporting database interfaces so they can continue to be used as column types
in things like gorm.io/gorm
.
Usage
The primarykey.ID
type is byte-compatible with UUIDs, and provides all the
interfaces required to be used as a database column type. For example, if you
have a gorm model:
import "go.b8s.dev/primarykey"
type MyModel struct {
ID primarykey.ID
}
There is also a public interface to encode and decode directly:
newOne := primarykey.New()
Encode(newOne) //=> "KwSysDpxcBU9FNhGkn2dCf"
id := Decode("KwSysDpxcBU9FNhGkn2dCf") //=> ID
id.UUID() //=> uuid.UUID
id.String() //=> "KwSysDpxcBU9FNhGkn2dCf"
Development
This is a very standard Go project with very minimal dependencies and no required setup. Dependencies are vendored.
To run the test suite,
$ go test .
That's about it.
# Functions
Decode parses the string as a shortuuid into an `ID`.
Empty returns a "valid", but zeroed-out UUID.
Encode takes an ID and encodes it to a shortuuid string.
No description provided by the author
MustDecode parses the string as an ID, similar to `Decode`, but panics if the string cannot be parsed.
New generates a new ID.
# Type aliases
ID is a type that stores the bytes of a UUID.