From 5cd9f422ea2637783e54f9789b8186c333eec4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Wed, 9 Oct 2024 21:04:10 +0200 Subject: [PATCH] Add utils (Debug, DebugBody, Sep...) --- utils/utils.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/utils/utils.go b/utils/utils.go index af2cc6e..fa07617 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -3,6 +3,8 @@ package utils import ( "bytes" + "encoding/json" + "fmt" "os" "text/template" ) @@ -28,3 +30,32 @@ func GenerateMarkdown(templatePath string, outputPath string, data map[string]in 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) +}