Documentation ¶
Index ¶
- Constants
- Variables
- func Assert(name string, context interface{}, value interface{}, op string) bool
- func Beautify(data interface{}) string
- func CalculateUID(node, sequence int64) int64
- func CompareValue(src, dst interface{}, op string) (bool, error)
- func Decode(input, output interface{}) error
- func DecodeJSON(input, output interface{}) error
- func DecodeString(str string) (interface{}, error)
- func DecodeTag(input, output interface{}, tag string) error
- func DenormalizeMSISDN(msisdn string, format MSISDNFormat) (string, error)
- func EncodeUID(uid int64) string
- func EpochToTime(epoch int64) time.Time
- func FieldExist(name string, val interface{}) bool
- func FindFieldByTag(obj interface{}, tag, key string) (string, error)
- func FindFieldTypeByTag(obj interface{}, tag, key string) (reflect.Type, error)
- func FromTimeHookFunc() mapstructure.DecodeHookFunc
- func GenerateRandNodeUID() int64
- func GenerateRandUID() int64
- func GenerateSeqUID() int64
- func GetClientIPAddress(r *http.Request) string
- func GetListenPort(hport string) string
- func GetNodeIDFromMac() int64
- func GetOffset(page, limit int) int
- func GetRandomNodeID() int64
- func GetRandomNumber() int64
- func GetSequenceNumber() int64
- func Hash(v interface{}) []byte
- func Hash58(v interface{}) string
- func Hash64(v interface{}) string
- func HashHex(v interface{}) string
- func IsMap(obj interface{}) bool
- func IsMapStringInterface(obj interface{}) bool
- func IsNumber(val interface{}) bool
- func IsPointerOfSlice(obj interface{}) bool
- func IsPointerOfStruct(obj interface{}) bool
- func IsSlice(obj interface{}) bool
- func IsStruct(obj interface{}) bool
- func IsStructOrPointerOf(obj interface{}) bool
- func IsTime(val interface{}) bool
- func ListTag(obj interface{}, tag string) ([]string, error)
- func Listen(hport string) (net.Listener, error)
- func Lookup(name string, context ...interface{}) (interface{}, bool)
- func Match(name string, context interface{}, value interface{}) bool
- func NormalizeMSISDN(msisdn string) (string, error)
- func Reverse(s interface{})
- func Serve(hport string, handler http.Handler, ...) error
- func SetValue(obj interface{}, key string, value interface{}) error
- func StringToDuration(s string) time.Duration
- func TimeToDateTimezone(setTime time.Time, timeZone string) time.Time
- func ToClock(timeData time.Time) string
- func ToTimeHookFunc(format string) mapstructure.DecodeHookFunc
- type DistributedPodID
- type ID
- func ParseBase2(id string) (ID, error)
- func ParseBase32(b []byte) (ID, error)
- func ParseBase36(id string) (ID, error)
- func ParseBase58(b []byte) (ID, error)
- func ParseBase64(id string) (ID, error)
- func ParseBytes(id []byte) (ID, error)
- func ParseInt64(id int64) ID
- func ParseIntBytes(id [8]byte) ID
- func ParseString(id string) (ID, error)
- func (f ID) Base2() string
- func (f ID) Base32() string
- func (f ID) Base36() string
- func (f ID) Base58() string
- func (f ID) Base64() string
- func (f ID) Bytes() []byte
- func (f ID) Int64() int64
- func (f ID) IntBytes() [8]byte
- func (f ID) MarshalJSON() ([]byte, error)
- func (f ID) Node() int64
- func (f ID) Step() int64
- func (f ID) String() string
- func (f ID) Time() int64
- func (f *ID) UnmarshalJSON(b []byte) error
- type ImageProxyOpt
- type JSONSyntaxError
- type MSISDNFormat
- type NodeIDGenerator
- type POD
- type SequenceGenerator
- type SnowflakeOpts
- type UID
Constants ¶
const ( //strict equal SE = "==" EQ = "=" GT = ">" GE = ">=" LT = "<" LE = "<=" //regex RE = "~" NE = "!=" SN = "!==" IN = "[]" EM = "{}" )
Variables ¶
var ( ErrPodIDExhausted = errors.New("all available pod id has been acquired") )
var ( // Epoch is set to the twitter snowflake epoch of Nov 04 2010 01:42:54 UTC in milliseconds // You may customize this to set a different epoch for your application. Epoch int64 = 1288834974657 //Default Epoch Time // PODBits holds the number of bits to use for Node // Remember, you have a total 22 bits to share between Node/Step PODBits uint8 = 10 // StepBits holds the number of bits to use for Step // Remember, you have a total 22 bits to share between POD/Step StepBits uint8 = 12 )
var ErrInvalidBase32 = errors.New("invalid base32")
ErrInvalidBase32 is returned by ParseBase32 when given an invalid []byte
var ErrInvalidBase58 = errors.New("invalid base58")
ErrInvalidBase58 is returned by ParseBase58 when given an invalid []byte
Functions ¶
func CalculateUID ¶
func CompareValue ¶
func DecodeJSON ¶
func DecodeJSON(input, output interface{}) error
func DecodeString ¶
func DenormalizeMSISDN ¶
func DenormalizeMSISDN(msisdn string, format MSISDNFormat) (string, error)
func EpochToTime ¶
func FieldExist ¶
func FindFieldByTag ¶
func FindFieldTypeByTag ¶
func FromTimeHookFunc ¶
func FromTimeHookFunc() mapstructure.DecodeHookFunc
func GenerateRandNodeUID ¶
func GenerateRandNodeUID() int64
GenerateRandNodeUID generate UID from random NodeID and random sequence number
func GenerateRandUID ¶
func GenerateRandUID() int64
GenerateRandUID generate UID with NodeID from network interface and random sequence number
func GenerateSeqUID ¶
func GenerateSeqUID() int64
GenerateSeqUID generate UID with NodeID from network interface and incremental sequence number
func GetClientIPAddress ¶
func GetListenPort ¶
applications need some way to access the infrastucture TODO: this method will work only after grace.Serve is called.
func GetNodeIDFromMac ¶
func GetNodeIDFromMac() int64
func GetRandomNodeID ¶
func GetRandomNodeID() int64
func GetRandomNumber ¶
func GetRandomNumber() int64
func GetSequenceNumber ¶
func GetSequenceNumber() int64
func IsMapStringInterface ¶
func IsMapStringInterface(obj interface{}) bool
func IsPointerOfSlice ¶
func IsPointerOfSlice(obj interface{}) bool
func IsPointerOfStruct ¶
func IsPointerOfStruct(obj interface{}) bool
func IsStructOrPointerOf ¶
func IsStructOrPointerOf(obj interface{}) bool
func NormalizeMSISDN ¶
func StringToDuration ¶
func ToTimeHookFunc ¶
func ToTimeHookFunc(format string) mapstructure.DecodeHookFunc
Types ¶
type DistributedPodID ¶
type DistributedPodID struct {
// contains filtered or unexported fields
}
func NewDistributedPodID ¶
type ID ¶
type ID int64
An ID is a custom type used for a snowflake ID. This is used so we can attach methods onto the ID.
func ParseBase2 ¶
ParseBase2 converts a Base2 string into a snowflake ID
func ParseBase32 ¶
ParseBase32 parses a base32 []byte into a snowflake ID NOTE: There are many different base32 implementations so careful when doing any interoperation.
func ParseBase36 ¶
ParseBase36 converts a Base36 string into a snowflake ID
func ParseBase58 ¶
ParseBase58 parses a base58 []byte into a snowflake ID
func ParseBase64 ¶
ParseBase64 converts a base64 string into a snowflake ID
func ParseBytes ¶
ParseBytes converts a byte slice into a snowflake ID
func ParseIntBytes ¶
ParseIntBytes converts an array of bytes encoded as big endian integer as a snowflake ID
func ParseString ¶
ParseString converts a string into a snowflake ID
func (ID) Base32 ¶
Base32 uses the z-base-32 character set but encodes and decodes similar to base58, allowing it to create an even smaller result string. NOTE: There are many different base32 implementations so becareful when doing any interoperation.
func (ID) IntBytes ¶
IntBytes returns an array of bytes of the snowflake ID, encoded as a big endian integer.
func (ID) MarshalJSON ¶
MarshalJSON returns a json byte array string of the snowflake ID.
func (ID) Node ¶
Node returns an int64 of the snowflake ID node number DEPRECATED: the below function will be removed in a future release.
func (ID) Step ¶
Step returns an int64 of the snowflake step (or sequence) number DEPRECATED: the below function will be removed in a future release.
func (ID) Time ¶
Time returns an int64 unix timestamp in milliseconds of the snowflake ID time DEPRECATED: the below function will be removed in a future release.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON converts a json byte array of a snowflake ID into an ID type.
type ImageProxyOpt ¶
type ImageProxyOpt struct { URL string Key string Salt string Resize string Width int Height int Gravity string Extension string Enlarge bool ProxyURL string }
func NewImageProxy ¶
func NewImageProxy(base, url, key, salt string) *ImageProxyOpt
func (*ImageProxyOpt) GetURL ¶
func (i *ImageProxyOpt) GetURL() (string, error)
type JSONSyntaxError ¶
type JSONSyntaxError struct {
// contains filtered or unexported fields
}
A JSONSyntaxError is returned from UnmarshalJSON if an invalid ID is provided.
func (JSONSyntaxError) Error ¶
func (j JSONSyntaxError) Error() string
type MSISDNFormat ¶
type MSISDNFormat string
const ( MSISDN08 MSISDNFormat = "08" MSISDN8 MSISDNFormat = "8" MSISDN62Plus MSISDNFormat = "62" )
type NodeIDGenerator ¶
type NodeIDGenerator func() int64
type POD ¶
type POD struct {
// contains filtered or unexported fields
}
A POD struct holds the basic information needed for a snowflake generator node
func NewPOD ¶
func NewPOD(o *SnowflakeOpts) (*POD, error)
NewPOD returns a new snowflake pod that can be used to generate snowflake IDs
type SequenceGenerator ¶
type SequenceGenerator func() int64
type SnowflakeOpts ¶
type UID ¶
type UID struct { NodeGen NodeIDGenerator SeqGen SequenceGenerator }
func NewUIDRandomNum ¶
func NewUIDRandomNum() *UID
func NewUIDSequenceNum ¶
func NewUIDSequenceNum() *UID