-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (46 loc) · 1.04 KB
/
Copy pathmain.go
File metadata and controls
52 lines (46 loc) · 1.04 KB
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
package main
import (
"context"
"github.com/core-go/config"
"github.com/core-go/core"
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/config")
if err != nil {
panic(err)
}
r := mux.NewRouter()
log.Initialize(cfg.Log)
r.Use(mid.BuildContext)
logger := mid.NewMaskLogger(MaskLog, MaskLog)
if log.IsInfoEnable() {
r.Use(mid.Logger(cfg.MiddleWare, log.InfoFields, logger))
}
r.Use(mid.Recover(log.PanicMsg))
ctx := context.Background()
err = app.Route(ctx, r, cfg)
if err != nil {
panic(err)
}
log.Info(ctx, core.ServerInfo(cfg.Server))
server := core.CreateServer(cfg.Server, r)
if err = server.ListenAndServe(); err != nil {
log.Error(ctx, err.Error())
}
}
func MaskLog(obj map[string]interface{}){
v, ok := obj["phone"]
if ok {
s, ok2 := v.(string)
if ok2 && len(s) > 3 {
obj["phone"] = strings.Mask(s, 0, 3, "*")
}
}
}