forked from lukasjarosch/genki
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
38 lines (32 loc) · 824 Bytes
/
options.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
package gateway
import (
"context"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/protobuf/proto"
"net/http"
)
type Options struct {
ResponseInterceptor ResponseInterceptorFunc
ServeMuxOpts []runtime.ServeMuxOption
}
type ResponseInterceptorFunc func(context.Context, http.ResponseWriter, proto.Message) error
func ResponseInterceptor(interceptor ResponseInterceptorFunc) Option {
return func(opt *Options) {
opt.ResponseInterceptor = interceptor
}
}
func WithServeMuxOptions(opts ...runtime.ServeMuxOption) Option {
return func(opt *Options) {
opt.ServeMuxOpts = append(opt.ServeMuxOpts, opts...)
}
}
func newOptions(opts ...Option) *Options {
opt := &Options{
ResponseInterceptor: nil,
}
for _, o := range opts {
o(opt)
}
return opt
}
type Option func(*Options)