server.go 620 B

123456789101112131415161718192021222324252627
  1. package grpc
  2. import (
  3. "context"
  4. "go-common/app/service/openplatform/anti-fraud/service"
  5. "go-common/library/net/rpc/warden"
  6. "google.golang.org/grpc"
  7. )
  8. //New 生成rpc服务
  9. func New(svc *service.Service) *warden.Server {
  10. s := warden.NewServer(nil)
  11. s.Use(middleware())
  12. _, err := s.Start()
  13. if err != nil {
  14. panic("run server failed!" + err.Error())
  15. }
  16. return s
  17. }
  18. func middleware() grpc.UnaryServerInterceptor {
  19. return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
  20. //call chain
  21. resp, err = handler(ctx, req)
  22. return
  23. }
  24. }