Remove all fmr.Println and add zerolog logging
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 1m52s
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 1m52s
This commit is contained in:
37
main.go
37
main.go
@@ -1,11 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/api"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/application"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/auth"
|
||||
@@ -18,6 +20,8 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
||||
|
||||
cfg, err := ReadConfig()
|
||||
|
||||
if err != nil {
|
||||
@@ -30,25 +34,30 @@ func main() {
|
||||
templates_public_dir = cfg.GetString("templates.public_dir")
|
||||
dev_env = cfg.GetBool("dev_env")
|
||||
)
|
||||
|
||||
if dev_env {
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
}
|
||||
|
||||
svc, err := services.NewServicesHandler(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Panic().Err(err).Msg("Error creating services handler")
|
||||
}
|
||||
|
||||
kv, err := cache.NewKVHandler(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Panic().Err(err).Msg("Error creating KV handler")
|
||||
}
|
||||
filestorage, _ := cache.NewFileStorage(cfg)
|
||||
|
||||
idp, err := identification.NewIdentificationProvider(cfg, svc, kv)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Panic().Err(err).Msg("Error creating identification provider")
|
||||
}
|
||||
|
||||
emailing, err := renderer.NewEmailingHandler(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Panic().Err(err).Msg("Error creating emailing handler")
|
||||
}
|
||||
|
||||
apiHandler, _ := api.NewAPIHandler(cfg, idp, svc, kv)
|
||||
@@ -56,11 +65,6 @@ func main() {
|
||||
exportsHandler, _ := exports.NewExportsHandler(cfg, svc, emailing)
|
||||
authHandler, _ := auth.NewAuthHandler(cfg, idp, svc, kv, emailing)
|
||||
|
||||
fmt.Println("Running", service_name, ":")
|
||||
if dev_env {
|
||||
fmt.Printf("\033]0;%s\007", service_name)
|
||||
}
|
||||
|
||||
r := mux.NewRouter()
|
||||
|
||||
r.PathPrefix("/public/").Handler(http.StripPrefix("/public/", http.FileServer(http.Dir(templates_public_dir))))
|
||||
@@ -72,7 +76,10 @@ func main() {
|
||||
r.HandleFunc("/auth/groups/", authHandler.Groups)
|
||||
r.HandleFunc("/auth/groups/switch", authHandler.GroupSwitch)
|
||||
r.HandleFunc("/", redirectApp)
|
||||
//r.Use(trackPage)
|
||||
|
||||
if dev_env {
|
||||
r.Use(trackPage)
|
||||
}
|
||||
|
||||
api_router := r.PathPrefix("/api").Subrouter()
|
||||
api_router.HandleFunc("/", apiHandler.NotFound)
|
||||
@@ -182,9 +189,9 @@ func main() {
|
||||
ReadTimeout: 15 * time.Second,
|
||||
}
|
||||
|
||||
fmt.Println("Running on ", address)
|
||||
log.Info().Str("service_name", service_name).Str("address", address).Msg("Running HTTP server")
|
||||
|
||||
log.Fatal(srv.ListenAndServe())
|
||||
log.Fatal().Err(srv.ListenAndServe())
|
||||
|
||||
}
|
||||
|
||||
@@ -194,7 +201,7 @@ func redirectApp(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func trackPage(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(r.RequestURI)
|
||||
log.Trace().Str("requested_uri", r.RequestURI).Msg("New request")
|
||||
next.ServeHTTP(w, r.WithContext(r.Context()))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user