Documentation
¶
Index ¶
- Variables
- type AnyMatcher
- type NullRefId
- type RefId
- func FromBase64String(input string) (RefId, error)
- func FromBytes(input []byte) (RefId, error)
- func FromHexString(input string) (RefId, error)
- func FromString(s string) (RefId, error)
- func Must(r RefId, err error) RefId
- func New() (RefId, error)
- func NewTagged(tag byte) (RefId, error)
- func Parse(s string) (RefId, error)
- func ParseTagged(tag byte, s string) (RefId, error)
- func (r RefId) Bytes() []byte
- func (r *RefId) ClearTag() *RefId
- func (r RefId) Equal(other RefId) bool
- func (r RefId) Format(f fmt.State, c rune)
- func (r RefId) HasTag(tag byte) bool
- func (r RefId) IsNil() bool
- func (r RefId) IsTagged() bool
- func (r RefId) MarshalBinary() ([]byte, error)
- func (r RefId) MarshalJSON() ([]byte, error)
- func (r RefId) MarshalText() ([]byte, error)
- func (r *RefId) Scan(src interface{}) error
- func (r *RefId) SetTag(tag byte) *RefId
- func (r *RefId) SetTime(ts time.Time) *RefId
- func (r RefId) String() string
- func (r RefId) Tag() byte
- func (r RefId) Time() time.Time
- func (r RefId) ToBase64String() string
- func (r RefId) ToHexString() string
- func (r RefId) ToString() string
- func (r *RefId) UnmarshalBinary(data []byte) error
- func (r *RefId) UnmarshalJSON(b []byte) error
- func (r *RefId) UnmarshalText(b []byte) error
- func (r RefId) Value() (driver.Value, error)
- type Tagger
Constants ¶
This section is empty.
Variables ¶
var ( // Nil is the nil RefId, that has all 128 bits set to zero. Nil = RefId{} )
Functions ¶
This section is empty.
Types ¶
type AnyMatcher ¶
type AnyMatcher struct {
// contains filtered or unexported fields
}
A matcher that supports the following interfaces:
func MatchAny ¶
func MatchAny(tag byte) AnyMatcher
Create a AnyMatcher matcher that matches that matches against a specific Tag. Any valid RefIds that do not match the tag specified, will be considered not matching.
If tag is 0, will support matching any RefId (tag is then ignored)
Example usage:
mock.ExpectQuery("^INSERT INTO some_table (.+)").
WithArgs(refid.MatchAny(1), 1).
WillReturnRows(rows)
func (AnyMatcher) Match ¶
func (a AnyMatcher) Match(v interface{}) bool
type NullRefId ¶
NullRefId can be used with the standard sql package to represent a RefId value that can be NULL in the database.
func (NullRefId) MarshalJSON ¶
MarshalJSON marshals the NullRefId as null or the nested RefId
func (*NullRefId) Scan ¶
Scan implements the sql.Scanner interface.
func (*NullRefId) UnmarshalJSON ¶
UnmarshalJSON unmarshals a NullRefId
type RefId ¶
type RefId [size]byte
A RefId is a 16 byte identifier that is:
- unix timestamp with microsecond precision 48 bits of microseconds from 1970 (about 2280 or so years worth)
- sql index friendly
- tagging support (support for 255 distinct tag types)
- supports go/sql scanner/valuer
- multiple encodings supported: native (base32), base64, base16 (hex)
- similar to UUIDv7, with different tradeoffs: slightly larger random section, tag support, no UUID version field, not an rfc standard
func FromBase64String ¶
FromBase64String parses a base64 string and returns a RefId. Returns an error if the base64 string is of improper size or otherwise fails to parse.
func FromBytes ¶
FromBytes creates a new RefId 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 FromHexString ¶
FromHexString parses a base16/hex string and returns a RefId. Returns an error if the base16/hex string is of improper size or otherwise fails to parse.
func Must ¶
Must is a helper that wraps a call to a function returning (RefId, error) and panics if the error is non-nil. It is intended for use in variable initializations such as
var (
refA = refid.Must(refid.New())
refB = refid.Must(refid.NewTagged(2))
refC = refid.Must(refid.Parse("0r2nbq0wqhjg186167t0gcd1gw"))
refD = refid.Must(refid.ParseTagged("0r2nbq0wqhjg186167t0gcd1gw", 2))
)
func NewTagged ¶
NewTagged returns a RefId tagged with tag.
If random bytes cannot be generated, it will return an error.
func Parse ¶
Parse parses a textual RefId representation, and returns a RefId. Supports parsing the following text formats:
- native/base32 (Crockford's alphabet)
- base64
- base16/hex
Will return an error on parse failure.
func ParseTagged ¶
ParseTagged parses a textual RefId representation (same formats as Parse),while additionally requiring the parsed RefId to be tagged with tag, and returns a RefId.
Returns an error if RefId fails to parse or if RefId is not tagged with tag.
func (RefId) Equal ¶
Equal compares a RefId to another RefId to see if they have the same underlying bytes.
func (RefId) Format ¶
Format implements the fmt.Formatter interface.
func (RefId) HasTag ¶
IsTagged reports whether the RefId is tagged and if so, if it is tagged with tag.
func (RefId) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (RefId) MarshalJSON ¶
MarshalJson implements the json.Marshaler interface.
func (RefId) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*RefId) Scan ¶
Scan implements the sql.Scanner interface. A 16-byte slice will be handled by RefId.UnmarshalBinary, while a longer byte slice or a string will be handled by RefId.UnmarshalText.
func (RefId) String ¶
String returns the native (base32 w/Crockford alphabet) textual represenation of a RefId
func (RefId) Tag ¶
Tag returns the current tag of the RefId. If the RefId is untagged, it will retrun 0.
func (RefId) ToBase64String ¶
String returns the base64 textual represenation of a RefId
func (RefId) ToHexString ¶
String returns the base16/hex textual represenation of a RefId
func (*RefId) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. It will return an error if the slice isn't of appropriate size.
func (*RefId) UnmarshalJSON ¶
UnmarshalJson implements the json.Unmarshaler interface.
func (*RefId) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. It will return an error if the slice isn't of appropriate size.
type Tagger ¶
type Tagger byte
A Tagger is a conveniece container for encoding and parsing RefId's of a specific tag.
func (Tagger) AnyMatcher ¶
func (t Tagger) AnyMatcher() AnyMatcher
AnyMather returns an AnyMatcher, which will match only against a RefId tagged with the same tag as the Tagger
func (Tagger) HasCorrectTag ¶
HasTag reports whether a RefId is tagged with the same tag as the Tagger
func (Tagger) IsTagged ¶
IsTagged reports wheater a RefId is tagged at all. Note: This only checks that the RefId is tagged, not that it is tagged with the same tag as Tagger. For that functionality use Tagger.HasCorrectTag.
