model

package
v1.9.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 8 Imported by: 14

Documentation

Index

Constants

View Source
const (
	BASE_64 = "base64"
)
View Source
const (
	BINARY = "binary"
)
View Source
const (
	BITS_8 = "bits8"
)
View Source
const (
	CIPHERED = "ciphered"
)
View Source
const (
	HASH = "hash"
)
View Source
const (
	KEY = "key"
)
View Source
const (
	SIGNATURE = "signature"
)
View Source
const (
	UUID_TYPE = "uuid"
)

Variables

This section is empty.

Functions

func CouldBeValidHash

func CouldBeValidHash(str string) bool

CouldBeValidHash returns `true` if the passed string could be a 32-bytes or 64-bytes hash in hexadecimal representation

func IsBase64String

func IsBase64String(str string) bool

IsBase64String ...

func IsBinaryString

func IsBinaryString(str string) bool

IsBinaryString ...

func IsBits8String

func IsBits8String(str string) bool

IsBits8String ...

func IsHexString added in v1.0.3

func IsHexString(str string) bool

IsHexString checks whether the passed string is an hexadecimal number of even length.

Types

type Base64

type Base64 string

Base64 is the base64 string representation of a byte array. NB: if the passed string is not a valid base64 representation, it will not throw an error but rather returns empty or nil items when methods are called.

func ToBase64

func ToBase64(bytes []byte) Base64

ToBase64 ...

func (Base64) Bytes

func (b Base64) Bytes() []byte

Bytes ...

func (Base64) IsEmpty added in v1.0.2

func (b Base64) IsEmpty() bool

IsEmpty ...

func (Base64) NonEmpty

func (b Base64) NonEmpty() bool

NonEmpty ...

func (Base64) String

func (b Base64) String() string

String ...

type Binary

type Binary string

Binary is the string representation of a binary literal, eg. Binary("1001") would equal to `0b1001` in other languages or starting with version 1.13 of Golang. NB: if the underlying string is not a valid string representation of a binary, it will not throw an error but rather return an empty or nil item for each method called.

func ToBinary

func ToBinary(bytes []byte) Binary

ToBinary ...

func (Binary) Bytes

func (b Binary) Bytes() []byte

Bytes ...

func (Binary) IsEmpty added in v1.0.2

func (b Binary) IsEmpty() bool

IsEmpty ...

func (Binary) NonEmpty

func (b Binary) NonEmpty() bool

NonEmpty ...

func (Binary) String

func (b Binary) String() string

String ...

type Bits8

type Bits8 uint8

Bits8 is an 8-bit representation of a bit set, ie. a single byte/octet

func StringToBits8

func StringToBits8(str string) (b Bits8, err error)

StringToBits8 ...

func ToBits8

func ToBits8(bytes []byte) Bits8

ToBits8 ...

func (Bits8) Bytes

func (b Bits8) Bytes() []byte

Bytes ...

func (*Bits8) Clear

func (b *Bits8) Clear(flag Bits8)

Clear ...

func (*Bits8) ClearAll

func (b *Bits8) ClearAll()

ClearAll ...

func (*Bits8) Has

func (b *Bits8) Has(flag Bits8) bool

Has ...

func (Bits8) IsEmpty added in v1.0.2

func (b Bits8) IsEmpty() bool

IsEmpty ...

func (Bits8) NonEmpty

func (b Bits8) NonEmpty() bool

NonEmpty ...

func (*Bits8) Set

func (b *Bits8) Set(flag Bits8)

Set ...

func (Bits8) String

func (b Bits8) String() string

String ...

func (*Bits8) Toggle

func (b *Bits8) Toggle(flag Bits8)

Toggle ...

type Ciphered

type Ciphered string

Ciphered is the base64 string representation of a ciphered text.

func ToCiphered

func ToCiphered(bytes []byte) Ciphered

ToCiphered ...

func (Ciphered) Bytes

func (c Ciphered) Bytes() []byte

Bytes returns the underlying byte array if it's an actual base64-encoded string, or nil.

func (Ciphered) IsEmpty added in v1.0.2

func (c Ciphered) IsEmpty() bool

IsEmpty ...

func (Ciphered) NonEmpty

func (c Ciphered) NonEmpty() bool

NonEmpty ...

func (Ciphered) String

func (c Ciphered) String() string

String returns the ciphered string if it's an actual base64-encoded string, or an empty string.

type Hash

type Hash string

Hash is the hexadecimal string representation of a hash.Hash It's either a 32-character, or a 64-character long and more.

func ToHash

func ToHash(bytes []byte) Hash

ToHash ...

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the underlying byte array if it's an actual hash string, or nil.

func (Hash) IsEmpty added in v1.0.2

func (h Hash) IsEmpty() bool

IsEmpty ...

func (Hash) NonEmpty

func (h Hash) NonEmpty() bool

NonEmpty ...

func (Hash) String

func (h Hash) String() string

String returns the hexadecimal string representation if it's an actual hash string, or an empty string.

type Hashes

type Hashes []Hash

Hashes is an array of Hash.

func (Hashes) Contains

func (h Hashes) Contains(item Hash) bool

Contains ...

func (*Hashes) Equals

func (h *Hashes) Equals(to *Hashes) bool

Equals ...

func (Hashes) Len

func (h Hashes) Len() int

func (Hashes) Less

func (h Hashes) Less(i, j int) bool

func (Hashes) Swap

func (h Hashes) Swap(i, j int)

type Key

type Key string

Key is the hexadecimal string representation of a public or private key.

func ToKey

func ToKey(bytes []byte) Key

ToKey ...

func (Key) Bytes

func (k Key) Bytes() []byte

Bytes ...

func (Key) IsEmpty added in v1.0.2

func (k Key) IsEmpty() bool

IsEmpty ...

func (Key) NonEmpty

func (k Key) NonEmpty() bool

NonEmpty ...

func (Key) String

func (k Key) String() string

String ...

type Keys

type Keys []Key

Keys is an array of Key.

func (Keys) Contains

func (k Keys) Contains(item Key) bool

Contains ...

func (*Keys) Equals added in v1.1.2

func (k *Keys) Equals(to *Keys) bool

Equals ...

func (Keys) Len added in v1.1.2

func (k Keys) Len() int

func (Keys) Less added in v1.1.2

func (k Keys) Less(i, j int) bool

func (Keys) Swap added in v1.1.2

func (k Keys) Swap(i, j int)

type Model

type Model interface {
	// Bytes returns the underlying byte array of the data
	Bytes() []byte

	// String returns the usual string representation of the data
	String() string

	// IsEmpty checks whether there is no data, ie. it's an empty byte array
	IsEmpty() bool

	// NonEmpty tells if the underlying data is not void
	NonEmpty() bool
}

Model defines the basic interface for each core model type.

All types should also define their own `To<TypeName>` function to get an object of the type from a byte array, eg. `func ToHash(bytes []byte) Hash` for the `Hash` type.

Invalid data for the `Model` type should not throw errors but rather act as if they were empty.

func ToModel added in v1.0.2

func ToModel(bytes []byte, typeName string) (m Model, err error)

ToModel is a factory utility. It takes the byte array of the data and the name of the type to return.

type Signature

type Signature string

Signature is the hexadecimal string representation of a signature.

func ToSignature

func ToSignature(bytes []byte) Signature

ToSignature ...

func (Signature) Bytes

func (s Signature) Bytes() []byte

Bytes ...

func (Signature) IsEmpty added in v1.0.2

func (s Signature) IsEmpty() bool

IsEmpty ...

func (Signature) NonEmpty

func (s Signature) NonEmpty() bool

NonEmpty ...

func (Signature) String

func (s Signature) String() string

String ...

type UUID

type UUID string

UUID is the string representation of a UUID, eg. 'e05572b3-230a-45fd-a779-604c2b8ceb24'

func GenerateUUID

func GenerateUUID() (id UUID, err error)

GenerateUUID creates a new UUID

func ToUUID

func ToUUID(bytes []byte) UUID

ToUUID ...

func (UUID) Bytes

func (u UUID) Bytes() []byte

Bytes ...

func (UUID) IsEmpty added in v1.0.2

func (u UUID) IsEmpty() bool

IsEmpty ...

func (UUID) NonEmpty

func (u UUID) NonEmpty() bool

NonEmpty ...

func (UUID) String

func (u UUID) String() string

String ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL