Improved logging with zap

This commit is contained in:
2025-09-16 12:23:12 +03:30
parent 5680f9471f
commit 6d15ce2df9
3 changed files with 18 additions and 16 deletions
+6 -4
View File
@@ -5,13 +5,15 @@ import (
"bytes"
"encoding/json"
"io"
"log/slog"
"net/http"
"net/url"
"go.uber.org/zap"
)
type GiteaOAuth2Handler struct {
cfg *config.Config
logger *zap.Logger
}
func NewGiteaOauth2Token(cfg *config.Config) *GiteaOAuth2Handler {
@@ -24,7 +26,7 @@ func (g *GiteaOAuth2Handler) GetGiteaLoginURL(redirectHost string) (string, erro
}
if redirectHost == "" {
slog.Error("Redirect host not provided")
g.logger.Error("Redirect host not provided")
return "", nil
}
@@ -35,7 +37,7 @@ func (g *GiteaOAuth2Handler) GetGiteaLoginURL(redirectHost string) (string, erro
func (g *GiteaOAuth2Handler) GetGiteaUserEmailByCode(code string) (string, error) {
if g.cfg.GiteaOauthInstance == "" {
slog.Error("Instance URL not provided")
g.logger.Error("Instance URL not provided")
return "", nil
}
// No need to verify since we are accesing the gitea once and only for the email
@@ -45,7 +47,7 @@ func (g *GiteaOAuth2Handler) GetGiteaUserEmailByCode(code string) (string, error
}
userInfoUrl := g.cfg.GiteaOauthInstance + "/login/oauth/userinfo"
slog.Info(userInfoUrl)
g.logger.Info(userInfoUrl)
req, err := http.NewRequest("POST", userInfoUrl, nil)
if err != nil {
return "", err