-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathoptions.go
More file actions
79 lines (67 loc) · 1.84 KB
/
options.go
File metadata and controls
79 lines (67 loc) · 1.84 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package kit
import (
"time"
"github.com/anthonycorbacho/workspace/kit/log"
"github.com/rs/cors"
"google.golang.org/grpc"
)
// FoundationOptions provides a set of configurable options for Foundation.
type FoundationOptions struct {
grpcAddr string
httpAddr string
grpcServerOpts []grpc.ServerOption
corsOpts cors.Options
enableCors bool
httpWriteTimeout time.Duration
httpReadTimeout time.Duration
logger *log.Logger
}
// Option defines a Foundation option.
type Option func(*FoundationOptions)
// WithGrpcServerOptions defines GRPC server options.
func WithGrpcServerOptions(opts ...grpc.ServerOption) Option {
return func(fo *FoundationOptions) {
fo.grpcServerOpts = opts
}
}
// EnableCors will add cors support to the http server.
func EnableCors() Option {
return func(fo *FoundationOptions) {
fo.enableCors = true
}
}
// WithCorsOptions defines http server cors options.
func WithCorsOptions(opts cors.Options) Option {
return func(fo *FoundationOptions) {
fo.corsOpts = opts
}
}
// WithGrpcAddr defines a GRPC server host and port.
func WithGrpcAddr(addr string) Option {
return func(fo *FoundationOptions) {
fo.grpcAddr = addr
}
}
// WithHTTPAddr defines a HTTP server host and port.
func WithHTTPAddr(addr string) Option {
return func(fo *FoundationOptions) {
fo.httpAddr = addr
}
}
// WithHTTPWriteTimeout defines write timeout for the HTTP server.
func WithHTTPWriteTimeout(timeout time.Duration) Option {
return func(fo *FoundationOptions) {
fo.httpWriteTimeout = timeout
}
}
// WithHTTPReadTimeout defines read timeout for the HTTP server.
func WithHTTPReadTimeout(timeout time.Duration) Option {
return func(fo *FoundationOptions) {
fo.httpReadTimeout = timeout
}
}
func WithLogger(logger *log.Logger) Option {
return func(fo *FoundationOptions) {
fo.logger = logger
}
}