-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.go
72 lines (56 loc) · 1.39 KB
/
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
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
69
70
71
72
package debug
import (
"net/http"
"github.com/alexfalkowski/go-service/errors"
sh "github.com/alexfalkowski/go-service/net/http"
"github.com/alexfalkowski/go-service/security"
"github.com/alexfalkowski/go-service/server"
"github.com/alexfalkowski/go-service/time"
"go.uber.org/fx"
"go.uber.org/zap"
)
// NewServeMux for debug.
func NewServeMux() *http.ServeMux {
return http.NewServeMux()
}
// ServerParams for debug.
type ServerParams struct {
fx.In
Shutdowner fx.Shutdowner
Mux *http.ServeMux
Config *Config
Logger *zap.Logger
}
// Server for debug.
type Server struct {
*server.Server
}
// NewServer for debug.
func NewServer(params ServerParams) (*Server, error) {
s := &http.Server{
Handler: params.Mux,
ReadTimeout: time.Timeout, WriteTimeout: time.Timeout,
IdleTimeout: time.Timeout, ReadHeaderTimeout: time.Timeout,
}
sv, err := sh.NewServer(s, config(params.Config))
if err != nil {
return nil, errors.Prefix("new debug server", err)
}
svr := server.NewServer("debug", sv, params.Logger, params.Shutdowner)
return &Server{Server: svr}, nil
}
func config(cfg *Config) sh.Config {
c := sh.Config{}
if !IsEnabled(cfg) {
return c
}
c.Enabled = true
c.Port = cfg.Port
if !security.IsEnabled(cfg.Security) {
return c
}
c.Security.Enabled = true
c.Security.CertFile = cfg.Security.CertFile
c.Security.KeyFile = cfg.Security.KeyFile
return c
}