package utils import ( "github.com/astaxie/beego/orm" "crypto/rand" "time" ) const ( dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ) func GetString(m orm.Params, param string) string { ret := "" switch i := m[param].(type) { case string: ret = i } return ret } func GetInt(m orm.Params, param string) int64 { var ret int64 ret = -1 switch i := m[param].(type) { case int, int32, int64: ret = i.(int64) } return ret } func GetBool(m orm.Params, param string) bool { var ret bool ret = false switch i := m[param].(type) { case bool: ret = i } return ret } func GetTime(m orm.Params, param string) time.Time { var ret time.Time switch i := m[param].(type) { case time.Time: ret = i } return ret } func TokenGenerator(length int) string { var bytes = make([]byte, length) if _, err := rand.Read(bytes); err != nil { panic(err) } for k, v := range bytes { bytes[k] = dictionary[v%byte(len(dictionary))] } return string(bytes) }