server.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package server
  2. import (
  3. "go-common/app/service/main/location/conf"
  4. "go-common/app/service/main/location/model"
  5. "go-common/app/service/main/location/service"
  6. "go-common/library/net/rpc"
  7. "go-common/library/net/rpc/context"
  8. )
  9. // RPC struct
  10. type RPC struct {
  11. s *service.Service
  12. }
  13. // New init 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. // Ping check connection success.
  23. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  24. return
  25. }
  26. // Archive get aid auth.
  27. func (r *RPC) Archive(c context.Context, a *model.Archive, res *int64) (err error) {
  28. var play int64
  29. if play, err = r.s.Auth(c, a.Aid, a.Mid, a.IP, a.CIP); err == nil {
  30. *res = play
  31. }
  32. return
  33. }
  34. // Archive2 get aid auth.
  35. func (r *RPC) Archive2(c context.Context, a *model.Archive, res *model.Auth) (err error) {
  36. var auth *model.Auth
  37. if auth, err = r.s.Archive2(c, a.Aid, a.Mid, a.IP, a.CIP); err == nil {
  38. *res = *auth
  39. }
  40. return
  41. }
  42. // Group get gid auth.
  43. func (r *RPC) Group(c context.Context, a *model.Group, res *model.Auth) (err error) {
  44. auth := r.s.AuthGID(c, a.Gid, a.Mid, a.IP, a.CIP)
  45. if auth != nil {
  46. *res = *auth
  47. }
  48. return
  49. }
  50. // AuthPIDs check if ip in pids.
  51. func (r *RPC) AuthPIDs(c context.Context, a *model.ArgPids, res *map[int64]*model.Auth) (err error) {
  52. *res, err = r.s.AuthPIDs(c, a.Pids, a.IP, a.CIP)
  53. return
  54. }
  55. // Info get IP info
  56. func (r *RPC) Info(c context.Context, a *model.ArgIP, res *model.Info) (err error) {
  57. var ti *model.Info
  58. if ti, err = r.s.Info(c, a.IP); err == nil {
  59. *res = *ti
  60. }
  61. return
  62. }
  63. // Infos get IPs infos.
  64. func (r *RPC) Infos(c context.Context, a []string, res *map[string]*model.Info) (err error) {
  65. *res, err = r.s.Infos(c, a)
  66. return
  67. }
  68. // InfoComplete get IP whole info.
  69. func (r *RPC) InfoComplete(c context.Context, a *model.ArgIP, res *model.InfoComplete) (err error) {
  70. var info *model.InfoComplete
  71. if info, err = r.s.InfoComplete(c, a.IP); err == nil {
  72. *res = *info
  73. }
  74. return
  75. }
  76. // InfosComplete get ips whole infos.
  77. func (r *RPC) InfosComplete(c context.Context, a []string, res *map[string]*model.InfoComplete) (err error) {
  78. *res, err = r.s.InfosComplete(c, a)
  79. return
  80. }