-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (35 loc) · 815 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
package main
import (
"context"
"fmt"
"github.com/core-go/config"
"github.com/core-go/core/cors"
svr "github.com/core-go/core/server"
mid "github.com/core-go/log/middleware"
"github.com/core-go/log/zap"
"github.com/gorilla/mux"
"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))
}
r.Use(mid.Recover(log.ErrorMsg))
err = app.Route(r, context.Background(), cfg)
if err != nil {
panic(err)
}
fmt.Println(svr.ServerInfo(cfg.Server))
c := cors.New(cfg.Allow)
handler := c.Handler(r)
svr.StartServer(cfg.Server, handler)
}