Documentation
¶
Overview ¶
Package guid helps generate and parse GUIDs.
GUIDs are similar to UUIDs (RFC 4122) but use are encoded using base32 to be more user-friendly.
A GUID is a 16 byte (128 bit) array and is compatible with standard UUIDs which is handy if you need to interoperate with other systems. GUID are stored in databases as a 16 byte array and thus can leverage native UUID types for better performances.
go test -bench=. pkg: github.com/bloom42/stdx/guid BenchmarkNewRandomPool/goroutines-4-4 12655129 94.50 ns/op BenchmarkNewRandomPool/goroutines-40-4 12680683 93.89 ns/op BenchmarkNewRandomPool/goroutines-2000-4 12629418 94.45 ns/op BenchmarkNewRandomPool/goroutines-4000-4 12702556 94.73 ns/op BenchmarkNewRandomPool/goroutines-8000-4 12450429 95.09 ns/op BenchmarkNewRandomReader/goroutines-40-4 6811862 154.2 ns/op BenchmarkNewRandomReader/goroutines-2000-4 6851259 165.7 ns/op BenchmarkNewRandomReader/goroutines-4000-4 7351102 158.5 ns/op BenchmarkNewRandomReader/goroutines-8000-4 7219173 154.8 ns/op BenchmarkNewRandomReader/goroutines-40000-4 7054268 159.7 ns/op
Index ¶
- Constants
- Variables
- type GUID
- func (guid GUID) Bytes() []byte
- func (guid GUID) Equal(other GUID) bool
- func (guid GUID) IsNil() bool
- func (guid GUID) MarshalBinary() ([]byte, error)
- func (guid GUID) MarshalText() ([]byte, error)
- func (guid *GUID) Scan(src interface{}) error
- func (guid GUID) String() string
- func (guid GUID) ToUuidString() string
- func (guid *GUID) UnmarshalBinary(data []byte) error
- func (guid *GUID) UnmarshalText(data []byte) error
- func (guid GUID) Value() (driver.Value, error)
Constants ¶
const (
Size = 16
)
Variables ¶
var ( ErrGuidIsNotValid = errors.New("GUID is not valid") ErrUuidIsNotValid = errors.New("Not a valid UUID") )
Functions ¶
This section is empty.
Types ¶
type GUID ¶
A GUID is a 128 bit (16 byte) Globally Unique IDentifier
var (
Empty GUID // empty GUID, all zeros
)
func FromBytes ¶
FromBytes creates a new GUID from a byte slice. Returns an error if the slice does not have a length of 16. The bytes are copied from the slice.
func NewTimeBased ¶
func NewTimeBased() GUID
func ParseUuidString ¶
Parse decodes s into a GUID as an UUID or returns an error. The form shoud be: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
func (GUID) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (GUID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*GUID) Scan ¶
Scan implements sql.Scanner so GUIDs can be read from databases transparently. Currently, database types that map to string and []byte are supported. Please consult database-specific driver documentation for matching types.
func (GUID) ToUuidString ¶
UUIDString returns the UUID string form of GUID, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
func (*GUID) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler.
func (*GUID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.