站点RPC方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
1.6 KiB

  1. package siterpc
  2. import (
  3. "encoding/json"
  4. "errors"
  5. )
  6. /**
  7. * 取所有配置
  8. * 2021/09/04
  9. * GZ
  10. */
  11. func GetAllConfig(site_id, dbname string, url ...string) ([]map[string]string, error) {
  12. if dbname == "" {
  13. return nil, errors.New("参数错误")
  14. }
  15. conn, err := rpc_server_conn(url...)
  16. if err != nil {
  17. return nil, err
  18. }
  19. defer conn.Close()
  20. arg := SiteConfigItemReqArg{site_id, dbname, ""}
  21. req, err := SetReqData(arg)
  22. if err != nil {
  23. return nil, err
  24. }
  25. res := &Response{}
  26. err = conn.GetAllConfig(req, res)
  27. if err != nil {
  28. return nil, err
  29. }
  30. res_data_de, err := GetResData(res)
  31. if err != nil {
  32. return nil, err
  33. }
  34. if res_data_de == "" {
  35. return nil, nil
  36. }
  37. var res_arr []map[string]string
  38. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  39. if err != nil {
  40. return nil, err
  41. }
  42. return res_arr, nil
  43. }
  44. /**
  45. * 分组下所有配置
  46. * 2021/09/04
  47. * GZ
  48. */
  49. func GetGroupConfig(site_id, dbname string, groupname string, url ...string) ([]map[string]string, error) {
  50. if dbname == "" {
  51. return nil, errors.New("参数错误")
  52. }
  53. conn, err := rpc_server_conn(url...)
  54. if err != nil {
  55. return nil, err
  56. }
  57. defer conn.Close()
  58. arg := SiteConfigItemReqArg{site_id, dbname, groupname}
  59. req, err := SetReqData(arg)
  60. if err != nil {
  61. return nil, err
  62. }
  63. res := &Response{}
  64. err = conn.GetGroupConfig(req, res)
  65. if err != nil {
  66. return nil, err
  67. }
  68. res_data_de, err := GetResData(res)
  69. if err != nil {
  70. return nil, err
  71. }
  72. if res_data_de == "" {
  73. return nil, nil
  74. }
  75. var res_arr []map[string]string
  76. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  77. if err != nil {
  78. return nil, err
  79. }
  80. return res_arr, nil
  81. }