-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (37 loc) · 1017 Bytes
/
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
package main
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
"github.com/thinkerou/favicon"
"go.uber.org/zap"
"github.com/lacazethomas/wakapi-stats/config"
"github.com/lacazethomas/wakapi-stats/handler"
)
func main() {
var logger *zap.Logger
var err error
gin.SetMode(gin.ReleaseMode)
appConfig := config.GetAppConfig()
// Set log level
if appConfig.IsDev() {
logger, err = zap.NewDevelopment()
} else {
logger, err = zap.NewProduction()
}
if err != nil {
log.Println("Error to initialize logger")
}
defer logger.Sync()
zap.ReplaceGlobals(logger)
r := gin.Default()
r.Use(favicon.New("./favicon.ico"))
r.GET("/api/v1/:type", handler.Summary)
r.GET("/", func(c *gin.Context) {
c.Data(http.StatusOK, "text/html; charset=utf-8", []byte("Hi 👋, this is an <a href=\"/api/v1/languages?url=https://stats-code.thomaslacaze.fr/api/v1/users/thomaslacaze/stats/30_days\">example</a>"))
})
err = r.Run(":8080")
if err != nil {
log.Println("Unable to start web server")
}
}