This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
service_def.go
58 lines (47 loc) · 1.52 KB
/
service_def.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package gateway
import (
"context"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"
)
type (
RegisterHandlerFromEndpoint func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)
ServiceDef struct {
name string
swagger []byte
Desc *grpc.ServiceDesc
Service interface{}
HandlerFromEndpointRegister RegisterHandlerFromEndpoint
}
Service interface {
Name() string
Swagger() []byte
GRPCDesc() *grpc.ServiceDesc
Impl() interface{}
GRPCGatewayRegister() func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)
}
)
func NewServiceDef(name string, swagger []byte, desc *grpc.ServiceDesc, service interface{}, registerHandler RegisterHandlerFromEndpoint) ServiceDef {
return ServiceDef{
name: name,
swagger: swagger,
Desc: desc,
Service: service,
HandlerFromEndpointRegister: registerHandler,
}
}
func (s ServiceDef) Name() string {
return s.name
}
func (s ServiceDef) Swagger() []byte {
return s.swagger
}
func (s ServiceDef) GRPCDesc() *grpc.ServiceDesc {
return s.Desc
}
func (s ServiceDef) Impl() interface{} {
return s.Service
}
func (s ServiceDef) GRPCGatewayRegister() func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
return s.HandlerFromEndpointRegister
}