fix: moved logging functions to its own package

This commit is contained in:
Simon Cornet 2025-03-06 08:47:02 +01:00
commit 13602ae71c
6 changed files with 64 additions and 55 deletions

View file

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"gogitlabber/cmd/gogitlabber/logging"
"net/http"
)
@ -27,16 +28,16 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
url := fmt.Sprintf("https://%s/api/v4/projects?%s&%s&%s%s",
gitlabHost, membership, order, perpage, archived)
logPrint("HTTP: Creating API request", nil)
logging.LogPrint(debug, "HTTP: Creating API request", nil)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, fmt.Errorf("ERROR: creating request: %v\n", err)
}
logPrint("HTTP: Adding PRIVATE-TOKEN header to API request", nil)
logging.LogPrint(debug, "HTTP: Adding PRIVATE-TOKEN header to API request", nil)
req.Header.Set("PRIVATE-TOKEN", gitlabToken)
logPrint("HTTP: Making request", nil)
logging.LogPrint(debug, "HTTP: Making request", nil)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
@ -48,7 +49,7 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
return nil, fmt.Errorf("ERROR: API request failed with status: %d\n", resp.StatusCode)
}
logPrint("HTTP: Decoding JSON response", nil)
logging.LogPrint(debug, "HTTP: Decoding JSON response", nil)
var repositories []Repository
if err := json.NewDecoder(resp.Body).Decode(&repositories); err != nil {
return nil, fmt.Errorf("ERROR: decoding response: %v\n", err)
@ -61,10 +62,10 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
repoCount := len(repositories)
err = bar.Set(0)
if err != nil {
logFatal("Could not reset the progressbar", err)
logging.LogFatal("Could not reset the progressbar", err)
}
bar.ChangeMax(repoCount)
logPrint("HTTP: Returning repositories found", nil)
logging.LogPrint(debug, "HTTP: Returning repositories found", nil)
return repositories, nil
}