-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (43 loc) · 1.03 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
package main
import (
"context"
"fmt"
"github.com/core-go/config"
sv "github.com/core-go/core"
"github.com/core-go/core/cors"
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"
"net/http"
"go-service/internal/app"
)
func main() {
var conf app.Config
err := config.Load(&conf, "configs/sql", "configs/config")
if err != nil {
panic(err)
}
r := mux.NewRouter()
log.Initialize(conf.Log)
r.Use(func(handler http.Handler) http.Handler {
return mid.BuildContextWithMask(handler, MaskLog)
})
logger := mid.NewLogger()
if log.IsInfoEnable() {
r.Use(mid.Logger(conf.MiddleWare, log.InfoFields, logger))
}
r.Use(mid.Recover(log.ErrorMsg))
err = app.Route(r, context.Background(), conf)
if err != nil {
panic(err)
}
c := cors.New(conf.Allow)
handler := c.Handler(r)
fmt.Println(sv.ServerInfo(conf.Server))
sv.StartServer(conf.Server, handler)
}
func MaskLog(name, s string) string {
return strings.Mask(s, 1, 6, "x")
}