-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.go
40 lines (32 loc) · 1.05 KB
/
router.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
package main
import(
"os"
"github.com/gorilla/mux"
"github.com/asccclass/serverstatus"
"github.com/asccclass/staticfileserver"
"github.com/asccclass/staticfileserver/libs/qrcode"
)
func NewRouter(srv *SherryServer.ShryServer, documentRoot string)(*mux.Router) {
router := mux.NewRouter()
// QRCode
var QRCode *qrcodeGeneratorService.QRCodeGenerator
if os.Getenv("QRCodePath") != "" {
var err error
QRCode, err = qrcodeGeneratorService.NewQRCodeGenerator(srv, os.Getenv("QRCodePath"))
if err == nil {
QRCode.AddRouter(router)
}
}
//logger
router.Use(SherryServer.ZapLogger(srv.Logger))
// health check
systemName := os.Getenv("SystemName")
m := serverstatus.NewServerStatus(systemName)
router.HandleFunc("/healthz", m.Healthz).Methods("GET")
// Geo Location
srv.GeoLocation.AddGeoLocationRouter(router)
// Static File server
staticfileserver := SherryServer.StaticFileServer{documentRoot, "index.html"}
router.PathPrefix("/").Handler(staticfileserver)
return router
}