server.go 741 B

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