package q5 import "io" import "strings" import "crypto/md5" import "encoding/hex" import "hash/crc32" const ( JSON_NONE = 0 JSON_ARRAY = iota JSON_OBJECT = iota ) func Md5Str(data string) string { h := md5.New() h.Write([]byte(data)) return hex.EncodeToString(h.Sum(nil)) } func Crc32(data string) uint32 { ieee := crc32.NewIEEE() io.WriteString(ieee, data) code := ieee.Sum32() return code } func JsonStrType(data string) int32 { arrayIdx := strings.IndexByte(data, '[') objectIdx := strings.IndexByte(data, '{') if arrayIdx < 0 && objectIdx < 0 { return JSON_NONE } else { if arrayIdx < 0 { return JSON_OBJECT } if objectIdx < 0 { return JSON_ARRAY } if arrayIdx < objectIdx { return JSON_ARRAY } else { return JSON_OBJECT } } }