Remove all fmr.Println and add zerolog logging
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 1m52s

This commit is contained in:
2024-11-11 19:50:17 +01:00
parent a51f077358
commit a8acc9950a
30 changed files with 333 additions and 325 deletions

View File

@@ -2,10 +2,11 @@ package api
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"github.com/rs/zerolog/log"
"github.com/gorilla/mux"
)
@@ -18,7 +19,7 @@ func (h APIHandler) GetCache(w http.ResponseWriter, r *http.Request) {
go func() {
d, err := h.cache.Get(cacheid)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
w.WriteHeader(http.StatusNotFound)
ch <- nil
return

View File

@@ -8,6 +8,7 @@ import (
"strconv"
"github.com/gorilla/mux"
"github.com/rs/zerolog/log"
)
type FlatMaps []map[string]any
@@ -48,7 +49,7 @@ func (h APIHandler) CacheExport(w http.ResponseWriter, r *http.Request) {
d, err := h.cache.Get(cacheid)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("Error getting cache")
w.WriteHeader(http.StatusNotFound)
return
}
@@ -56,7 +57,6 @@ func (h APIHandler) CacheExport(w http.ResponseWriter, r *http.Request) {
if data, ok := d.([]any); ok {
flatmaps := FlatMaps{}
//fmt.Println(data)
for _, v := range data {
fm := map[string]any{}
@@ -90,7 +90,7 @@ func flatten(prefix string, src map[string]any, dest map[string]any) {
dest[prefix+k+"."+strconv.Itoa(i)] = child[i]
}
default:
fmt.Println(prefix+k, " : ", v)
// log.Trace().Str("key", prefix+k).Any("value", v).Msg("")
dest[prefix+k] = v
}
}

View File

@@ -2,15 +2,15 @@ package api
import (
"context"
"fmt"
"net/http"
"github.com/rs/zerolog/log"
)
func (h APIHandler) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
oauth2Token, err := h.idp.OAuth2Config.Exchange(context.Background(), r.URL.Query().Get("code"))
if err != nil {
fmt.Println("Exchange error")
fmt.Println(err)
log.Error().Err(err).Msg("Exchange error")
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -18,17 +18,14 @@ func (h APIHandler) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
// Extract the ID Token from OAuth2 token.
rawIDToken, ok := oauth2Token.Extra("id_token").(string)
if !ok {
fmt.Println("issue retrieving token")
log.Error().Msg("Cannot retrieve ID token")
w.WriteHeader(http.StatusInternalServerError)
return
}
fmt.Println(rawIDToken)
_, err = h.idp.TokenVerifier.Verify(context.Background(), rawIDToken)
if err != nil {
fmt.Println("not able to verify token")
fmt.Println(err)
log.Error().Err(err).Msg("Not able to verify token")
w.WriteHeader(http.StatusUnauthorized)
return
}
@@ -44,7 +41,7 @@ func (h APIHandler) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
}
if err = session.Save(r, w); err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("Cannot save session")
w.WriteHeader(http.StatusInternalServerError)
return
}