server.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package grpc
  2. import (
  3. "context"
  4. pb "go-common/app/admin/main/manager/api"
  5. "go-common/app/admin/main/manager/service"
  6. "go-common/library/log"
  7. "go-common/library/net/rpc/warden"
  8. )
  9. // server .
  10. type server struct {
  11. srv *service.Service
  12. }
  13. // New return warden server.
  14. func New(cfg *warden.ServerConfig, srv *service.Service) *warden.Server {
  15. w := warden.NewServer(cfg)
  16. pb.RegisterPermitServer(w.Server(), &server{srv: srv})
  17. var err error
  18. if w, err = w.Start(); err != nil {
  19. panic(err)
  20. }
  21. return w
  22. }
  23. // Login whether login .
  24. func (s *server) Login(ctx context.Context, req *pb.LoginReq) (*pb.LoginReply, error) {
  25. sid, uname, err := s.srv.Login(ctx, req.Mngsid, req.Dsbsid)
  26. if err != nil {
  27. return nil, err
  28. }
  29. return &pb.LoginReply{Sid: sid, Username: uname}, nil
  30. }
  31. // Permissions .
  32. func (s *server) Permissions(ctx context.Context, req *pb.PermissionReq) (*pb.PermissionReply, error) {
  33. tmp, err := s.srv.Permissions(ctx, req.Username)
  34. if err != nil {
  35. log.Error("s.Permissions error(%v)", err)
  36. return nil, err
  37. }
  38. return &pb.PermissionReply{Uid: tmp.UID, Perms: tmp.Perms}, nil
  39. }