-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (43 loc) · 1.05 KB
/
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
44
45
46
47
48
49
50
package main
import (
"context"
"github.com/core-go/config"
"github.com/core-go/core/header"
"github.com/core-go/core/random"
srv "github.com/core-go/core/server"
mid "github.com/core-go/log/middleware"
"github.com/core-go/log/zap"
"github.com/gorilla/mux"
_ "github.com/lib/pq"
"go-service/internal/app"
)
func main() {
var cfg app.Config
err := config.Load(&cfg, "configs/config")
if err != nil {
panic(err)
}
r := mux.NewRouter()
log.Initialize(cfg.Log)
r.Use(mid.BuildContext)
logger := mid.NewLogger()
if log.IsInfoEnable() {
r.Use(mid.Logger(cfg.MiddleWare, log.InfoFields, logger))
}
headerHandler := header.NewHeaderHandler(cfg.Response, GenerateId)
r.Use(headerHandler.HandleHeader())
r.Use(mid.Recover(log.PanicMsg))
ctx := context.Background()
err = app.Route(ctx, r, cfg)
if err != nil {
panic(err)
}
log.Info(ctx, srv.ServerInfo(cfg.Server))
server := srv.CreateServer(cfg.Server, r)
if err = server.ListenAndServe(); err != nil {
log.Error(ctx, err.Error())
}
}
func GenerateId() string {
return random.Random(16)
}