Add utils (Debug, DebugBody, Sep...)

main
Óscar M. Lage 2024-10-09 21:04:10 +02:00
parent fb4f5c7ed6
commit 5cd9f422ea
1 changed files with 31 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package utils
import ( import (
"bytes" "bytes"
"encoding/json"
"fmt"
"os" "os"
"text/template" "text/template"
) )
@ -28,3 +30,32 @@ func GenerateMarkdown(templatePath string, outputPath string, data map[string]in
return os.WriteFile(outputPath, output.Bytes(), 0644) return os.WriteFile(outputPath, output.Bytes(), 0644)
} }
func Debug(v interface{}, args ...string) {
// utils.Debug(variable)
debug, err := json.MarshalIndent(v, "", " ")
if err != nil {
fmt.Println("Error marshaling JSON:", err)
return
}
// Print a title if there is one
if len(args) > 0 {
fmt.Printf("%s\n", args[0])
}
fmt.Printf("DEBUG:\n%s\n", string(debug))
}
func DebugBody(body []byte) {
// utils.DebugBody(body)
var jsonResponse interface{}
err := json.Unmarshal(body, &jsonResponse)
if err != nil {
fmt.Println("Error unmarshaling JSON:", err)
}
Debug(jsonResponse, "--API RESPONSE--")
}
func Sep() {
separator := "════════════════════════════════════════════════"
fmt.Println(separator)
}