forked from filecoin-project/go-jsonrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions_server.go
More file actions
41 lines (33 loc) · 841 Bytes
/
options_server.go
File metadata and controls
41 lines (33 loc) · 841 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
36
37
38
39
40
41
package jsonrpc
import (
"context"
"reflect"
)
type ParamDecoder func(ctx context.Context, json []byte) (reflect.Value, error)
type ServerConfig struct {
paramDecoders map[reflect.Type]ParamDecoder
maxRequestSize int64
errors *Errors
}
type ServerOption func(c *ServerConfig)
func defaultServerConfig() ServerConfig {
return ServerConfig{
paramDecoders: map[reflect.Type]ParamDecoder{},
maxRequestSize: DEFAULT_MAX_REQUEST_SIZE,
}
}
func WithParamDecoder(t interface{}, decoder ParamDecoder) ServerOption {
return func(c *ServerConfig) {
c.paramDecoders[reflect.TypeOf(t).Elem()] = decoder
}
}
func WithMaxRequestSize(max int64) ServerOption {
return func(c *ServerConfig) {
c.maxRequestSize = max
}
}
func WithServerErrors(es Errors) ServerOption {
return func(c *ServerConfig) {
c.errors = &es
}
}