-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
63 lines (48 loc) · 928 Bytes
/
web.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
package web
import (
"context"
log "github.com/sirupsen/logrus"
"net/http"
"github.com/go-chi/chi"
)
type Web struct {
config *WebConfig
http *http.Server
}
func NewWeb(httpConf *WebConfig, mux http.Handler) (*Web, error) {
h := &http.Server{
Addr: httpConf.Addr(),
Handler: mux,
ReadTimeout: httpConf.ReadTimeout,
WriteTimeout: httpConf.WriteTimeout,
}
web := &Web{
config: httpConf,
http: h,
}
return web, nil
}
func (a *Web) NewRouter() chi.Router {
return chi.NewRouter()
}
func (a *Web) ListenAndServer() error {
log.Infof("web: Listen %s", a.config.Addr())
if err := a.http.ListenAndServe(); err != nil {
return nil
}
return nil
}
func (a *Web) Close() error {
err := a.http.Close()
if err != nil {
return err
}
return nil
}
func (a *Web) Shutdown(ctx context.Context) error {
err := a.http.Shutdown(ctx)
if err != nil {
return err
}
return nil
}