digest

package
v3.14.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2017 License: Apache-2.0, Apache-2.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const DigestTagName = "digest"

Variables

View Source
var Logger = log.NewDefaultLogger("WARN")

Functions

func DigestStruct

func DigestStruct(input interface{}, sumFunc SumFunc) []byte

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 Md5SumFunc(v []byte) []byte

func NoByteFunc

func NoByteFunc() []byte

Gets the function provides constant no byte(empty array)

func NonZeroBytesFunc

func NonZeroBytesFunc() []byte

func SumAll

func SumAll(sumFunc SumFunc, rest ...Digestor) []byte

Sums all of the digestors with customized sum function

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

type DigestableTime time.Time

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 Digestor

type Digestor interface {
	GetDigest() []byte
}

Gets the digest of MD5

type DigestorFunc

type DigestorFunc func() []byte

Function object for Digestor

func (DigestorFunc) GetDigest

func (f DigestorFunc) GetDigest() []byte

type Md5DigestValue

type Md5DigestValue [md5.Size]byte

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

type SumFunc

type SumFunc func([]byte) []byte

Jump to

Keyboard shortcuts

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