-
Notifications
You must be signed in to change notification settings - Fork 37
/
opts.go
40 lines (34 loc) · 1.05 KB
/
opts.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
package httptransport
import (
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/utrack/clay/v2/transport/swagger"
"google.golang.org/grpc"
)
// DescOptions provides options for a ServiceDesc compiled code.
type DescOptions struct {
UnaryInterceptor grpc.UnaryServerInterceptor
SwaggerDefaultOpts []swagger.Option
}
// OptionUnaryInterceptor sets up the gRPC unary interceptor.
type OptionUnaryInterceptor struct {
Interceptor grpc.UnaryServerInterceptor
}
// Apply implements transport.DescOption.
func (o OptionUnaryInterceptor) Apply(oo *DescOptions) {
if oo.UnaryInterceptor != nil {
oo.UnaryInterceptor = grpc_middleware.ChainUnaryServer(
oo.UnaryInterceptor,
o.Interceptor,
)
return
}
oo.UnaryInterceptor = o.Interceptor
}
// OptionSwaggerOpts sets up default options for the SwaggerDef().
type OptionSwaggerOpts struct {
Options []swagger.Option
}
// Apply implements transport.DescOption.
func (o OptionSwaggerOpts) Apply(oo *DescOptions) {
oo.SwaggerDefaultOpts = append(oo.SwaggerDefaultOpts, o.Options...)
}