当前位置: 首页 > 工具软件 > Go Debug > 使用案例 >

Golang debug code

充培
2023-12-01

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))
 类似资料:

相关阅读

相关文章

相关问答