-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (55 loc) · 1.38 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"context"
"fmt"
"net/http"
"github.com/core-go/config"
"github.com/core-go/core/server"
"github.com/core-go/log/convert"
gm "github.com/core-go/log/gin"
"github.com/core-go/log/strings"
"github.com/core-go/log/zap"
"github.com/gin-gonic/gin"
_ "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)
}
cfg.MiddleWare.Constants = convert.ToCamelCase(cfg.MiddleWare.Constants)
cfg.MiddleWare.Map = convert.ToCamelCase(cfg.MiddleWare.Map)
g := gin.New()
log.Initialize(cfg.Log)
formatter := gm.NewMaskLogger(cfg.MiddleWare.Request, Mask, Mask)
logger := gm.NewGinLogger(cfg.MiddleWare, log.InfoFields, formatter, MaskLog)
g.Use(logger.BuildContextWithMask())
g.Use(logger.Logger())
g.Use(gin.Recovery())
err = app.Route(context.Background(), g, cfg)
if err != nil {
panic(err)
}
fmt.Println(server.ServerInfo(cfg.Server))
if err = http.ListenAndServe(server.Addr(cfg.Server.Port), g); err != nil {
fmt.Println(err.Error())
}
}
func MaskLog(name, s string) string {
if name == "mobileNo" {
return strings.Mask(s, 2, 2, "x")
} else {
return strings.Mask(s, 0, 5, "x")
}
}
func Mask(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, "*")
}
}
}