-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
35 lines (30 loc) · 900 Bytes
/
options.go
File metadata and controls
35 lines (30 loc) · 900 Bytes
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
package mrpc
// ServerOption represents an option which can be used to configure
// an mrpc server.
type ServerOption func(*serverOptions) error
type serverOptions struct {
interceptors []ServerInterceptor
}
func defaultServerOptions() serverOptions {
return serverOptions{}
}
func (o *serverOptions) apply(opts []ServerOption) error {
for _, opt := range opts {
if err := opt(o); err != nil {
return err
}
}
return nil
}
// WithServerInterceptor adds an interceptor for method calls on the
// server side. It is possible to add multiple interceptors. In thas
// case they are executed in the order they are provided.
func WithServerInterceptor(interceptor ServerInterceptor) ServerOption {
return func(o *serverOptions) error {
if interceptor == nil {
return optionError("no interceptor specified")
}
o.interceptors = append(o.interceptors, interceptor)
return nil
}
}