-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (43 loc) · 1.04 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"
"fmt"
"net/http"
"github.com/core-go/core/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/strings"
"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/sql", "configs/config")
if err != nil {
panic(err)
}
r := mux.NewRouter()
log.Initialize(cfg.Log)
r.Use(func(handler http.Handler) http.Handler {
return mid.BuildContextWithMask(handler, MaskLog)
})
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)
}
c := cors.New(cfg.Allow)
handler := c.Handler(r)
fmt.Println(svr.ServerInfo(cfg.Server))
svr.StartServer(cfg.Server, handler)
}
func MaskLog(name, s string) string {
return strings.Mask(s, 1, 6, "x")
}