updated dependencies
This commit is contained in:
parent
fc1912bfa9
commit
de35d43aa7
4 changed files with 68 additions and 27 deletions
|
|
@ -2,7 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"context"
|
||||
//stdtls "crypto/tls"
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
|
@ -31,9 +31,8 @@ type Server struct {
|
|||
stop chan struct{}
|
||||
stopKeyReset chan struct{}
|
||||
|
||||
cert string
|
||||
key string
|
||||
laddr string
|
||||
cert tls.Certificate
|
||||
listen net.Listener
|
||||
}
|
||||
|
||||
type notFoundHandler struct {
|
||||
|
|
@ -45,7 +44,7 @@ func (nf *notFoundHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// NewHTTPServer returns a new HTTPServer
|
||||
func NewServer(c *config.Config, log logr.Logger) *Server {
|
||||
func NewServer(c *config.Config, log logr.Logger) (*Server, error) {
|
||||
s := &Server{
|
||||
mux: mux.NewRouter(),
|
||||
log: log,
|
||||
|
|
@ -58,17 +57,24 @@ func NewServer(c *config.Config, log logr.Logger) *Server {
|
|||
init: make(chan struct{}),
|
||||
stop: make(chan struct{}),
|
||||
stopKeyReset: make(chan struct{}),
|
||||
|
||||
cert: c.Server.TLS.Cert,
|
||||
key: c.Server.TLS.Key,
|
||||
laddr: c.Server.Listen,
|
||||
}
|
||||
cert, err := tls.LoadX509KeyPair(c.Server.TLS.Cert, c.Server.TLS.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.cert = cert
|
||||
l, err := net.Listen("tcp", c.Server.Listen)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.listen = l
|
||||
|
||||
s.mux.NotFoundHandler = ¬FoundHandler{s}
|
||||
for _, v := range serverv1.Routes {
|
||||
s.mux.HandleFunc(v.Path, s.contextWrapper(v.Handler)).Methods(v.Methods...)
|
||||
}
|
||||
s.start()
|
||||
return s
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateDB(db *db.DB) error {
|
||||
|
|
@ -86,26 +92,41 @@ func (s *Server) UpdateDB(db *db.DB) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) start() error {
|
||||
func (s *Server) start() {
|
||||
<-s.init
|
||||
l, err := net.Listen("tcp", s.laddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO tls config
|
||||
s.srv = &http.Server{
|
||||
Handler: s.mux,
|
||||
//TLSConfig: cfg,
|
||||
TLSConfig: &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
CipherSuites: []uint16{
|
||||
tls.TLS_AES_256_GCM_SHA384,
|
||||
tls.TLS_CHACHA20_POLY1305_SHA256,
|
||||
tls.TLS_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||
},
|
||||
CurvePreferences: []tls.CurveID{
|
||||
tls.X25519,
|
||||
tls.CurveP384,
|
||||
tls.CurveP521,
|
||||
},
|
||||
PreferServerCipherSuites: true,
|
||||
Certificates: []tls.Certificate{s.cert},
|
||||
},
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
}
|
||||
go func() {
|
||||
err := s.srv.Serve(l)
|
||||
err := s.srv.Serve(s.listen)
|
||||
if err != nil {
|
||||
s.log.Error(err, "")
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Server) contextWrapper(h types.CtxHandler) http.HandlerFunc {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue