platformconfig.pb.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package proto
  2. import (
  3. "context"
  4. "bet24.com/log"
  5. "bet24.com/servers/micros/common"
  6. "github.com/smallnest/rpcx/client"
  7. )
  8. const ServiceName = "platformconfig"
  9. const NOTIFY_MESSAGE = "RefreshRedisConfig"
  10. var consulAddr = common.Default_Consul_Addr
  11. func getClient() client.XClient {
  12. return common.GetClientPool().GetClient(ServiceName, consulAddr)
  13. }
  14. type Request struct {
  15. Name string
  16. Value string
  17. }
  18. type Response struct {
  19. Data string
  20. List []string
  21. }
  22. func SetConsulAddr(addr string) {
  23. consulAddr = addr
  24. }
  25. func SayHello(name string) string {
  26. xclient := getClient()
  27. args := &Request{
  28. Name: name,
  29. }
  30. reply := &Response{}
  31. err := xclient.Call(context.Background(), "SayHello", args, reply)
  32. if err != nil {
  33. log.Debug("platformconfig failed to call: %v", err)
  34. common.GetClientPool().RemoveClient(ServiceName)
  35. return ""
  36. }
  37. log.Debug("SayHello return %s", reply.Data)
  38. return reply.Data
  39. }
  40. func GetConfig(name string) string {
  41. xclient := getClient()
  42. args := &Request{
  43. Name: name,
  44. }
  45. reply := &Response{}
  46. err := xclient.Call(context.Background(), "GetConfig", args, reply)
  47. if err != nil {
  48. log.Debug("platformconfig failed to call: %v", err)
  49. common.GetClientPool().RemoveClient(ServiceName)
  50. return ""
  51. }
  52. return reply.Data
  53. }
  54. func SetConfig(name string, value string) {
  55. xclient := getClient()
  56. args := &Request{
  57. Name: name,
  58. Value: value,
  59. }
  60. err := xclient.Call(context.Background(), "SetConfig", args, nil)
  61. if err != nil {
  62. log.Debug("platformconfig failed to call: %v", err)
  63. common.GetClientPool().RemoveClient(ServiceName)
  64. return
  65. }
  66. }
  67. func GetConfigList() []string {
  68. xclient := getClient()
  69. args := &Request{}
  70. reply := &Response{}
  71. err := xclient.Call(context.Background(), "GetConfigList", args, reply)
  72. if err != nil {
  73. log.Debug("platformconfig failed to call: %v", err)
  74. common.GetClientPool().RemoveClient(ServiceName)
  75. return []string{}
  76. }
  77. return reply.List
  78. }
  79. func GetChangeLog(key string) string {
  80. xclient := getClient()
  81. args := &Request{Name: key}
  82. reply := &Response{}
  83. err := xclient.Call(context.Background(), "GetChangeLog", args, reply)
  84. if err != nil {
  85. log.Debug("platformconfig failed to call: %v", err)
  86. common.GetClientPool().RemoveClient(ServiceName)
  87. return ""
  88. }
  89. return reply.Data
  90. }