Add utils (Debug, DebugBody, Sep...)
This commit is contained in:
parent
fb4f5c7ed6
commit
5cd9f422ea
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user