server.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Package grpc generate by warden_gen
  2. package grpc
  3. import (
  4. "context"
  5. "go-common/app/service/main/open/api/grpc/v1"
  6. "go-common/app/service/main/open/service"
  7. "go-common/library/ecode"
  8. "go-common/library/net/rpc/warden"
  9. )
  10. // New Open warden rpc server
  11. func New(c *warden.ServerConfig, svr *service.Service) *warden.Server {
  12. w := warden.NewServer(c)
  13. v1.RegisterOpenServer(w.Server(), &openService{svr})
  14. ws, err := w.Start()
  15. if err != nil {
  16. panic(err)
  17. }
  18. return ws
  19. }
  20. type openService struct {
  21. svr *service.Service
  22. }
  23. var _ v1.OpenServer = &openService{}
  24. // Ping check dao health.
  25. func (s *openService) Ping(ctx context.Context, req *v1.PingReq) (*v1.PingReply, error) {
  26. return nil, ecode.MethodNotAllowed
  27. }
  28. // Close close all dao.
  29. func (s *openService) Close(ctx context.Context, req *v1.CloseReq) (*v1.CloseReply, error) {
  30. return nil, ecode.MethodNotAllowed
  31. }
  32. // Secret .
  33. func (s *openService) Secret(ctx context.Context, req *v1.SecretReq) (*v1.SecretReply, error) {
  34. return nil, ecode.MethodNotAllowed
  35. }
  36. // AppID .
  37. func (s *openService) AppID(ctx context.Context, req *v1.AppIDReq) (*v1.AppIDReply, error) {
  38. appID, err := s.svr.AppID(ctx, req.AppKey)
  39. if err != nil {
  40. return nil, err
  41. }
  42. appIDReply := &v1.AppIDReply{
  43. AppId: appID,
  44. }
  45. return appIDReply, nil
  46. }