-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
42 lines (38 loc) · 827 Bytes
/
server.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
package server
import (
"crypto/tls"
"crypto/x509"
"fmt"
"net/http"
"sync"
)
type Server struct {
sync.WaitGroup
sync.RWMutex
*http.Server
}
func New() *Server {
return &Server{
Server: &http.Server{
TLSConfig: &tls.Config{
// TLS versions below 1.2 are considered insecure
// see https://www.rfc-editor.org/rfc/rfc7525.txt for details
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{},
ClientCAs: &x509.CertPool{},
ClientAuth: tls.NoClientCert,
},
},
}
}
func (s *Server) Configure(c *Configuration) error {
tlsConfig, err := getTlsConfig(c)
if err != nil {
return err
}
s.Server.Addr = fmt.Sprintf("%s:%s", c.Address, c.Port)
s.Server.ReadTimeout = c.ReadTimeout
s.Server.WriteTimeout = c.WriteTimeout
s.Server.TLSConfig = tlsConfig
return nil
}