-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
52 lines (44 loc) · 1.15 KB
/
options.go
File metadata and controls
52 lines (44 loc) · 1.15 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
package http
import (
"crypto/tls"
)
// Options are the http server options.
type Options struct {
VersionedAPIs map[string][]API
APIs []API
Hostname string
Port int
TLSConfig *tls.Config
}
// Option is a function that changes options in some way.
type Option func(o *Options)
// WithAPI is a server option that stores provided API in given http server.
func WithAPI(api API) Option {
return func(o *Options) {
o.APIs = append(o.APIs, api)
}
}
// WithAPIVersion is a server option that stores the api for provided version.
func WithAPIVersion(version string, api API) Option {
return func(o *Options) {
o.VersionedAPIs[version] = append(o.VersionedAPIs[version], api)
}
}
// WithPort sets the port option for the server.
func WithPort(port int) Option {
return func(o *Options) {
o.Port = port
}
}
// WithHostname sets the hostname option for the server.
func WithHostname(hostname string) Option {
return func(o *Options) {
o.Hostname = hostname
}
}
// WithTLSConfig sets the tls config option for the server.
func WithTLSConfig(tlsConfig *tls.Config) Option {
return func(o *Options) {
o.TLSConfig = tlsConfig
}
}