mysql.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/infra/databus/model"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _getAuthSQL = `SELECT auth.group_name,auth.operation,app.app_key,app.app_secret,auth.topic,app.cluster
  9. FROM auth LEFT JOIN app ON auth.app_id=app.id`
  10. _getAuth2SQL = `SELECT auth2.group,auth2.operation,app2.app_key,app2.app_secret,auth2.number,topic.topic,topic.cluster
  11. FROM auth2 LEFT JOIN app2 On auth2.app_id=app2.id LEFT JOIN topic On topic.id=auth2.topic_id WHERE auth2.app_id!=0 AND auth2.is_delete=0`
  12. )
  13. // Auth verify group,topic,key
  14. func (d *Dao) Auth(c context.Context) (auths map[string]*model.Auth, err error) {
  15. auths = make(map[string]*model.Auth)
  16. // auth
  17. rows, err := d.db.Query(c, _getAuthSQL)
  18. if err != nil {
  19. log.Error("getAuthStmt.Query error(%v)", err)
  20. return
  21. }
  22. defer rows.Close()
  23. for rows.Next() {
  24. a := &model.Auth{}
  25. if err = rows.Scan(&a.Group, &a.Operation, &a.Key, &a.Secret, &a.Topic, &a.Cluster); err != nil {
  26. log.Error("rows.Scan error(%v)", err)
  27. return
  28. }
  29. auths[a.Group] = a
  30. }
  31. // auth2
  32. rows2, err := d.db.Query(c, _getAuth2SQL)
  33. if err != nil {
  34. log.Error("getAuthStmt.Query error(%v)", err)
  35. return
  36. }
  37. defer rows2.Close()
  38. for rows2.Next() {
  39. a := &model.Auth{}
  40. if err = rows2.Scan(&a.Group, &a.Operation, &a.Key, &a.Secret, &a.Batch, &a.Topic, &a.Cluster); err != nil {
  41. log.Error("rows.Scan error(%v)", err)
  42. return
  43. }
  44. auths[a.Group] = a
  45. }
  46. return
  47. }