v0.3.1版本
来源,#338
- 全局SetDebug
package main
import (
"fmt"
"github.com/guonaihong/gout"
)
func main() {
gout.SetDebug(true)
err := gout.GET(":8080/colorjson").Do()
if err != nil {
fmt.Printf("err is:%v\n")
}
}
- 请求保存到文件里面
import (
"github.com/guonaihong/gout"
"github.com/guonaihong/gout/debug"
)
func main() {
err := gout.POST(":8080/colorjson").
Debug(debug.ToFile("./req.txt", false)).
SetJSON(gout.H{"str": "foo",
"num": 100,
"bool": false,
"null": nil,
"array": gout.A{"foo", "bar", "baz"},
"obj": gout.H{"a": 1, "b": 2},
}).Do()
if err != nil {
fmt.Printf("err = %v\n", err)
}
}
- 请求保存到io.Writer里面, bytes.Buffer, 文件都可存放
package main
import (
"bytes"
"fmt"
"github.com/guonaihong/gout"
"github.com/guonaihong/gout/debug"
)
func main() {
var buf bytes.Buffer
err := gout.POST(":8080/colorjson").
Debug(debug.ToWriter(&buf, false)).
SetJSON(gout.H{"str": "foo",
"num": 100,
"bool": false,
"null": nil,
"array": gout.A{"foo", "bar", "baz"},
"obj": gout.H{"a": 1, "b": 2},
}).Do()
if err != nil {
fmt.Printf("err = %v\n", err)
}
fmt.Println(buf.String())
}