Golang debug code
echo out
func outMsg(msg string) {
call(fmt.Sprintf("echo '%s' >>/rootfs/1.log", msg))
}
func call(command string) {
cmd := exec.Command("bash", "-c", command)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
if err != nil {
fmt.Println(err)
}
err1 := cmd.Wait()
if err1 != nil {
fmt.Println(err1)
}
}
pretty print map
func debugPrettyPrintMap(x map[string]interface{}) string {
b, err := json.MarshalIndent(x, "", " ")
if err != nil {
fmt.Println("error:", err)
}
return string(b)
}
print HTTP request
// Save a copy of this request for debugging.
requestDump, err := httputil.DumpRequest(req, true)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(requestDump))