config.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package config
  2. import (
  3. "context"
  4. "go-common/app/infra/config/model"
  5. "go-common/library/net/rpc"
  6. )
  7. const (
  8. _appid = "config.service"
  9. _push = "RPC.Push"
  10. _setToken = "RPC.SetToken"
  11. _pushV4 = "RPC.PushV4"
  12. _force = "RPC.Force"
  13. _setTokenV4 = "RPC.SetTokenV4"
  14. _hosts = "RPC.Hosts"
  15. _clearHost = "RPC.ClearHost"
  16. )
  17. var (
  18. _noArg = &struct{}{}
  19. )
  20. //Service2 service.
  21. type Service2 struct {
  22. client *rpc.Client2
  23. }
  24. // New2 new a config service.
  25. func New2(c *rpc.ClientConfig) (s *Service2) {
  26. s = &Service2{}
  27. s.client = rpc.NewDiscoveryCli(_appid, c)
  28. return
  29. }
  30. // Push push new ver to config-service
  31. func (s *Service2) Push(c context.Context, arg *model.ArgConf) (err error) {
  32. err = s.client.Boardcast(c, _push, arg, _noArg)
  33. return
  34. }
  35. // SetToken update token in config-service
  36. func (s *Service2) SetToken(c context.Context, arg *model.ArgToken) (err error) {
  37. err = s.client.Boardcast(c, _setToken, arg, _noArg)
  38. return
  39. }
  40. // PushV4 push new ver to config-service
  41. func (s *Service2) PushV4(c context.Context, arg *model.ArgConf) (err error) {
  42. err = s.client.Boardcast(c, _pushV4, arg, _noArg)
  43. return
  44. }
  45. // SetTokenV4 update token in config-service
  46. func (s *Service2) SetTokenV4(c context.Context, arg *model.ArgToken) (err error) {
  47. err = s.client.Boardcast(c, _setTokenV4, arg, _noArg)
  48. return
  49. }
  50. //Hosts get host list.
  51. func (s *Service2) Hosts(c context.Context, svr string) (hosts []*model.Host, err error) {
  52. err = s.client.Call(c, _hosts, svr, &hosts)
  53. return
  54. }
  55. // ClearHost update token in config-service
  56. func (s *Service2) ClearHost(c context.Context, svr string) (err error) {
  57. err = s.client.Call(c, _clearHost, svr, _noArg)
  58. return
  59. }
  60. // Force push new host ver to config-service
  61. func (s *Service2) Force(c context.Context, arg *model.ArgConf) (err error) {
  62. err = s.client.Boardcast(c, _force, arg, _noArg)
  63. return
  64. }