This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
/
conf.go
68 lines (59 loc) · 1.52 KB
/
conf.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
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
package http
import (
"crypto/tls"
"errors"
"time"
)
// ServerTLS represents the TLS configurations
type ServerTLS struct {
Config *tls.Config
CertificateFilePath string
PrivateKeyFilePath string
}
// Clone creates an exact detached copy of the server TLS configurations
func (stls *ServerTLS) Clone() *ServerTLS {
if stls == nil {
return nil
}
var config *tls.Config
if stls.Config != nil {
config = stls.Config.Clone()
}
return &ServerTLS{
Config: config,
CertificateFilePath: stls.CertificateFilePath,
PrivateKeyFilePath: stls.PrivateKeyFilePath,
}
}
// ServerConfig defines the HTTP server transport layer configurations
type ServerConfig struct {
Host string
KeepAliveDuration time.Duration
TLS *ServerTLS
Playground bool
}
// Prepare sets defaults and validates the configurations
func (conf *ServerConfig) Prepare() error {
if conf.KeepAliveDuration == time.Duration(0) {
conf.KeepAliveDuration = 3 * time.Minute
}
if conf.TLS != nil {
if conf.TLS.CertificateFilePath == "" {
return errors.New("missing TLS certificate file path")
}
if conf.TLS.PrivateKeyFilePath == "" {
return errors.New("missing TLS private key file path")
}
}
return nil
}
// ClientConfig defines the HTTP client transport layer configuration
type ClientConfig struct {
Timeout time.Duration
}
// SetDefaults sets the default configuration
func (conf *ClientConfig) SetDefaults() {
if conf.Timeout == time.Duration(0) {
conf.Timeout = 30 * time.Second
}
}