go-common/app/job/main/passport-user-compare/dao/secret.go

34 lines
736 B
Go
Raw Normal View History

2019-04-22 10:49:16 +00:00
package dao
import (
"context"
"go-common/app/job/main/passport-user-compare/model"
xsql "go-common/library/database/sql"
"go-common/library/log"
)
var (
secretSQL = "SELECT us.key_type, us.key FROM user_secret us"
)
// LoadSecret load secret
func (d *Dao) LoadSecret(c context.Context) (res []*model.Secret, err error) {
var rows *xsql.Rows
if rows, err = d.secretDB.Query(c, secretSQL); err != nil {
log.Error("fail to get secretSQL, dao.secretDB.Query(%s) error(%v)", secretSQL, err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Secret)
if err = rows.Scan(&r.KeyType, &r.Key); err != nil {
log.Error("row.Scan() error(%v)", err)
res = nil
return
}
res = append(res, r)
}
return
}