-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoption.go
61 lines (53 loc) · 1.16 KB
/
option.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
package httpstub
type config struct {
useTLS bool
cacert, cert, key []byte
clientCacert, clientCert, clientKey []byte
}
type Option func(*config) error
// UseTLS enable TLS
func UseTLS() Option {
return func(c *config) error {
c.useTLS = true
return nil
}
}
// Certificates set certificates ( cert, key )
func Certificates(cert, key []byte) Option {
return func(c *config) error {
c.cert = cert
c.key = key
return nil
}
}
// CACert set CA
func CACert(cacert []byte) Option {
return func(c *config) error {
c.cacert = cacert
return nil
}
}
// UseTLSWithCertificates enable TLS with certificates ( cert, key )
func UseTLSWithCertificates(cert, key []byte) Option {
return func(c *config) error {
c.useTLS = true
c.cert = cert
c.key = key
return nil
}
}
// ClientCertificates set client certificates ( cert, key )
func ClientCertificates(cert, key []byte) Option {
return func(c *config) error {
c.clientCert = cert
c.clientKey = key
return nil
}
}
// ClientCACert set client CA
func ClientCACert(cacert []byte) Option {
return func(c *config) error {
c.clientCacert = cacert
return nil
}
}