Skip to content

Commit

Permalink
Merge pull request #3 from maquanyi/develop
Browse files Browse the repository at this point in the history
Add backend driver setting value in global setting
  • Loading branch information
genedna committed Aug 3, 2015
2 parents 79d0b7b + 128651b commit a3d4c15
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
DBURI string
DBPasswd string
DBDB int64
BackendDriver string //Container image storage driver name
)

func SetConfig(path string) error {
Expand Down Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package utils

import (
"crypto/md5"
"encoding/base64"
"encoding/hex"
"fmt"
"os"
"regexp"
"strings"
"time"
)

func Exist(filename string) bool {
Expand Down Expand Up @@ -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))
}

0 comments on commit a3d4c15

Please sign in to comment.