Documentation ¶
Index ¶
- Constants
- Variables
- func DigestStruct(input interface{}, sumFunc SumFunc) []byte
- func Md5SumFunc(v []byte) []byte
- func NoByteFunc() []byte
- func NonZeroBytesFunc() []byte
- func SumAll(sumFunc SumFunc, rest ...Digestor) []byte
- func ZeroBytesFunc() []byte
- type BytesGetter
- type BytesMd5Digestor
- type DigestableTime
- type Digestor
- type DigestorFunc
- type Md5DigestValue
- type StringMd5Digestor
- type SumFunc
Constants ¶
const DigestTagName = "digest"
Variables ¶
var Logger = log.NewDefaultLogger("WARN")
Functions ¶
func DigestStruct ¶
This package supports the digesting on struct:
type MyStruct type { Name string `digest:1` Age int `digest:2` }
Constructs the struct tag and performs digesting ¶
Digesting rule on field: []byte(<field name> +'|') bytes on fields
If field is the type of "interface{}", this type would be purified into more accurate type, which makes the digesting more easy.
Supporting type on field:
buildin types of golang pointers of buildin types of golang array types(element could be any type or pointer types) the type implementing Digestor "interface{}"
Fields could implement Digestor for customized bytes of your object:
type sha1String string func (s sha1String) GetDigest() []byte { digest := sha1.Sum([]byte(s)) return digest[:] }
According to the "sequence" part of tag value, the digest value of every field would be concated to a stream of bytes and use sumFunc to digest the final result.
For nested structs, the inner one would be digested(by sumFunc) as stream of bytes.
For bool values:
true - []byte{ 1 } false - []byte{ 0 }
func Md5SumFunc ¶
func NonZeroBytesFunc ¶
func NonZeroBytesFunc() []byte
func ZeroBytesFunc ¶
func ZeroBytesFunc() []byte
Gets the function provides constant zero bytes(not empty array)
Types ¶
type BytesGetter ¶
type BytesGetter func() []byte
func GetBytesGetter ¶
func GetBytesGetter(v interface{}, sumFunc SumFunc) BytesGetter
Gets the bytes getter by any value, this function could be used to implement your own DigestStruct
type BytesMd5Digestor ¶
type BytesMd5Digestor []byte
func (BytesMd5Digestor) GetDigest ¶
func (d BytesMd5Digestor) GetDigest() []byte
type DigestableTime ¶
This type is used to digest time value
func (DigestableTime) GetDigest ¶
func (t DigestableTime) GetDigest() []byte
Generates digest by the unix value of time
if time.Time.IsZero() is true, use NoByteFunc as the digest value
type DigestorFunc ¶
type DigestorFunc func() []byte
Function object for Digestor
func (DigestorFunc) GetDigest ¶
func (f DigestorFunc) GetDigest() []byte
type Md5DigestValue ¶
func SumAllToMd5 ¶
func SumAllToMd5(rest ...Digestor) Md5DigestValue
This function would call Digestor.GetDigest() and "glue" every value of digestor together.
type StringMd5Digestor ¶
type StringMd5Digestor string
func (StringMd5Digestor) GetDigest ¶
func (d StringMd5Digestor) GetDigest() []byte