-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (36 loc) · 851 Bytes
/
main.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
package api
import (
"context"
"net"
"time"
"github.com/rarimo/relayer-svc/internal/config"
"gitlab.com/distributed_lab/ape"
"gitlab.com/distributed_lab/kit/copus/types"
"gitlab.com/distributed_lab/logan/v3"
"gitlab.com/distributed_lab/logan/v3/errors"
)
type api struct {
log *logan.Entry
copus types.Copus
listener net.Listener
cfg config.Config
}
func Run(cfg config.Config, ctx context.Context) {
s := &api{
log: cfg.Log(),
copus: cfg.Copus(),
listener: cfg.Listener(),
cfg: cfg,
}
r := s.router()
if err := s.copus.RegisterChi(r); err != nil {
panic(errors.Wrap(err, "cop failed"))
}
s.log.WithFields(logan.F{
"service": "api",
"addr": cfg.Listener().Addr(),
}).Info("listening for http requests")
ape.Serve(ctx, r, cfg, ape.ServeOpts{
WriteTimeout: time.Second * 30,
})
}