rpc.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package server
  2. import (
  3. "go-common/app/service/main/seq-server/conf"
  4. "go-common/app/service/main/seq-server/model"
  5. "go-common/app/service/main/seq-server/service"
  6. "go-common/library/net/rpc"
  7. "go-common/library/net/rpc/context"
  8. )
  9. // RPC rpc.
  10. type RPC struct {
  11. s *service.Service
  12. }
  13. // New creates rpc server.
  14. func New(c *conf.Config, s *service.Service) (svr *rpc.Server) {
  15. r := &RPC{s: s}
  16. svr = rpc.NewServer(c.RPCServer)
  17. if err := svr.Register(r); err != nil {
  18. panic(err)
  19. }
  20. return
  21. }
  22. // Auth check connection success.
  23. func (r *RPC) Auth(c context.Context, arg *rpc.Auth, res *struct{}) (err error) {
  24. return
  25. }
  26. // Ping check connection success.
  27. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  28. if err = r.s.Ping(c); err != model.ErrBusinessNotReady {
  29. err = nil
  30. }
  31. return
  32. }
  33. // ID return id.
  34. func (r *RPC) ID(c context.Context, a *model.ArgBusiness, res *int64) (err error) {
  35. *res, err = r.s.ID(c, a.BusinessID, a.Token)
  36. return
  37. }
  38. // ID32 return id32.
  39. func (r *RPC) ID32(c context.Context, a *model.ArgBusiness, res *int32) (err error) {
  40. *res, err = r.s.ID32(c, a.BusinessID, a.Token)
  41. return
  42. }
  43. // CheckVersion check db health.
  44. func (r *RPC) CheckVersion(c context.Context, arg *struct{}, res *model.SeqVersion) (err error) {
  45. var seqVer *model.SeqVersion
  46. if seqVer, err = r.s.CheckVersion(c); err == nil {
  47. *res = *seqVer
  48. }
  49. return
  50. }