diff --git a/db/db.go b/db/db.go index ad6229f..e5d9e14 100644 --- a/db/db.go +++ b/db/db.go @@ -99,6 +99,7 @@ func InitDB(addr, passwd string, db int64) error { func Save(obj interface{}, key string) (err error) { result, err := json.Marshal(&obj) + if err != nil { return err } @@ -112,6 +113,7 @@ func Save(obj interface{}, key string) (err error) { func Get(obj interface{}, key string) (err error) { result, err := Client.Get(key).Result() + if err != nil { return err } diff --git a/setting/setting.go b/setting/setting.go index cbfe224..84c0e28 100644 --- a/setting/setting.go +++ b/setting/setting.go @@ -21,6 +21,7 @@ var ( DBURI string DBPasswd string DBDB int64 + BackendDriver string //Container image storage driver name ) func SetConfig(path string) error { @@ -103,5 +104,11 @@ func SetConfig(path string) error { DBDB, err = conf.Int64("db::db") + if backenddriver := conf.String("backend::driver"); backenddriver != "" { + BackendDriver = backenddriver + } else if backenddriver == "" { + err = fmt.Errorf("BackendDriver config value is null") + } + return err } diff --git a/utils/utils.go b/utils/utils.go index 2d9b48e..56e0b56 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1,11 +1,14 @@ package utils import ( + "crypto/md5" "encoding/base64" + "encoding/hex" "fmt" "os" "regexp" "strings" + "time" ) func Exist(filename string) bool { @@ -77,3 +80,11 @@ func ValidatePassword(password string) error { return nil } + +func MD5(key string) string { + md5String := fmt.Sprintf("%s%d", key, time.Now().Unix()) + h := md5.New() + h.Write([]byte(md5String)) + + return hex.EncodeToString(h.Sum(nil)) +}