feat: using github.com/scornet256/go-logger
This commit is contained in:
parent
6f3224c9cc
commit
cf33cc31f4
10 changed files with 61 additions and 110 deletions
|
|
@ -3,8 +3,9 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gogitlabber/cmd/gogitlabber/logging"
|
||||
"net/http"
|
||||
|
||||
"github.com/scornet256/go-logger"
|
||||
)
|
||||
|
||||
func fetchRepositoriesGitlab() ([]Repository, error) {
|
||||
|
|
@ -28,16 +29,16 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
|
|||
url := fmt.Sprintf("https://%s/api/v4/projects?%s&%s&%s%s",
|
||||
gitlabHost, membership, order, perpage, archived)
|
||||
|
||||
logging.Print("HTTP: Creating API request", nil)
|
||||
logger.Print("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)
|
||||
}
|
||||
|
||||
logging.Print("HTTP: Adding PRIVATE-TOKEN header to API request", nil)
|
||||
logger.Print("HTTP: Adding PRIVATE-TOKEN header to API request", nil)
|
||||
req.Header.Set("PRIVATE-TOKEN", gitlabToken)
|
||||
|
||||
logging.Print("HTTP: Making request", nil)
|
||||
logger.Print("HTTP: Making request", nil)
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
|
@ -49,7 +50,7 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
|
|||
return nil, fmt.Errorf("ERROR: API request failed with status: %d\n", resp.StatusCode)
|
||||
}
|
||||
|
||||
logging.Print("HTTP: Decoding JSON response", nil)
|
||||
logger.Print("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,19 +62,19 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
|
|||
|
||||
repoCount := len(repositories)
|
||||
|
||||
logging.Print("BAR: Resetting the progressbar", nil)
|
||||
logger.Print("BAR: Resetting the progressbar", nil)
|
||||
if !debug {
|
||||
err = bar.Set(0)
|
||||
if err != nil {
|
||||
logging.Fatal("Could not reset the progressbar", err)
|
||||
logger.Fatal("Could not reset the progressbar", err)
|
||||
}
|
||||
}
|
||||
|
||||
logging.Print("BAR: Increasing the max value of the progressbar", nil)
|
||||
logger.Print("BAR: Increasing the max value of the progressbar", nil)
|
||||
if !debug {
|
||||
bar.ChangeMax(repoCount)
|
||||
}
|
||||
|
||||
logging.Print("HTTP: Returning repositories found", nil)
|
||||
logger.Print("HTTP: Returning repositories found", nil)
|
||||
return repositories, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue