secret.go 736 B

123456789101112131415161718192021222324252627282930313233
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/passport-user-compare/model"
  5. xsql "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. var (
  9. secretSQL = "SELECT us.key_type, us.key FROM user_secret us"
  10. )
  11. // LoadSecret load secret
  12. func (d *Dao) LoadSecret(c context.Context) (res []*model.Secret, err error) {
  13. var rows *xsql.Rows
  14. if rows, err = d.secretDB.Query(c, secretSQL); err != nil {
  15. log.Error("fail to get secretSQL, dao.secretDB.Query(%s) error(%v)", secretSQL, err)
  16. return
  17. }
  18. defer rows.Close()
  19. for rows.Next() {
  20. r := new(model.Secret)
  21. if err = rows.Scan(&r.KeyType, &r.Key); err != nil {
  22. log.Error("row.Scan() error(%v)", err)
  23. res = nil
  24. return
  25. }
  26. res = append(res, r)
  27. }
  28. return
  29. }