站点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.

78 lines
1.3 KiB

  1. package siterpc
  2. import (
  3. "encoding/json"
  4. "log"
  5. "strconv"
  6. "time"
  7. "git.tetele.net/tgo/crypter"
  8. "github.com/golang/protobuf/proto"
  9. )
  10. type SiteInfoReq struct {
  11. Master string
  12. Host string
  13. }
  14. type SiteInfoRes struct {
  15. SiteId string `json:"site_id"`
  16. Dbname string `json:"database"`
  17. Domainname string `json:"domainname"`
  18. }
  19. /**
  20. * 由host取对应站点关键信息
  21. * 请求及回均加密验签
  22. * 2021/06/24
  23. * GZ
  24. */
  25. func GetSiteInfoByHost(master, host string, url ...string) (*SiteInfoRes, error) {
  26. conn, err := rpc_server_conn(url...)
  27. if err != nil {
  28. return nil, err
  29. }
  30. defer conn.Close()
  31. arg := SiteInfoReq{master, host}
  32. data_json, err := json.Marshal(arg)
  33. if err != nil {
  34. return nil, err
  35. }
  36. now_int64 := time.Now().Unix()
  37. encryData := crypter.DesEn(string(data_json), DES_KEY)
  38. now := strconv.FormatInt(now_int64, 10)
  39. sign := Sign(encryData, now)
  40. req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}
  41. res := &Response{}
  42. err = conn.GetSiteInfoByHost(req, res)
  43. if err != nil {
  44. return nil, err
  45. }
  46. res_data, err := GetOrgData(res)
  47. log.Println(res_data, err)
  48. if err != nil {
  49. return nil, err
  50. }
  51. var res_arr SiteInfoRes
  52. err = json.Unmarshal([]byte(res_data), &res_arr)
  53. if err != nil {
  54. return nil, err
  55. }
  56. return &res_arr, nil
  57. }