app_auth.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/msm/model"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _allAppInfoSQL = "SELECT app_tree_id,app_id,`limit` FROM app"
  9. _allAppAuthSQL = "SELECT service_tree_id,app_tree_id,rpc_method,http_method,quota,mtime FROM app_auth"
  10. )
  11. // AllAppsInfo AllAppsInfo.
  12. func (d *Dao) AllAppsInfo(c context.Context) (res map[int64]*model.AppInfo, err error) {
  13. rows, err := d.db.Query(c, _allAppInfoSQL)
  14. if err != nil {
  15. log.Error("d.apmDB.Query(app) error(%v)", err)
  16. return
  17. }
  18. defer rows.Close()
  19. res = make(map[int64]*model.AppInfo)
  20. for rows.Next() {
  21. app := &model.AppInfo{}
  22. if err = rows.Scan(&app.AppTreeID, &app.AppID, &app.Limit); err != nil {
  23. log.Error("rows.Scan(app) error(%v)", err)
  24. return
  25. }
  26. res[app.AppTreeID] = app
  27. }
  28. return
  29. }
  30. // AllAppsAuth get all app auth info.
  31. func (d *Dao) AllAppsAuth(c context.Context) (res map[int64]map[int64]*model.AppAuth, err error) {
  32. rows, err := d.db.Query(c, _allAppAuthSQL)
  33. if err != nil {
  34. log.Error("d.apmDB.Query(app_auth) error(%v)", err)
  35. return
  36. }
  37. defer rows.Close()
  38. res = make(map[int64]map[int64]*model.AppAuth)
  39. for rows.Next() {
  40. appAuth := &model.AppAuth{}
  41. if err = rows.Scan(&appAuth.ServiceTreeID, &appAuth.AppTreeID, &appAuth.RPCMethod, &appAuth.HTTPMethod, &appAuth.Quota, &appAuth.MTime); err != nil {
  42. log.Error("rows.Scan(appAuth) error(%v)", err)
  43. return
  44. }
  45. if _, b := res[appAuth.ServiceTreeID]; b {
  46. res[appAuth.ServiceTreeID][appAuth.AppTreeID] = appAuth
  47. } else {
  48. authMap := make(map[int64]*model.AppAuth)
  49. authMap[appAuth.AppTreeID] = appAuth
  50. res[appAuth.ServiceTreeID] = authMap
  51. }
  52. }
  53. return
  54. }