goreqGo HTTP request 庫(kù)
goreq
goreq是一個(gè)力求最簡(jiǎn)化的golang http request庫(kù),簡(jiǎn)化僅僅是指使用方法比較簡(jiǎn)單, 但功能卻一點(diǎn)不弱,
簡(jiǎn)單到極致的普通的request
req := goreq.Req(nil)
body,_,_ := req.Get("https://www.baidu.com").Do()
fmt.Print(string(body))
使用以下幾行代碼就可以完成一個(gè)反向代理工具:
package main
import (
"net/http"
"github.com/xioxu/goreq"
)
func main() {
if err := http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
req := goreq.Req(&goreq.ReqOptions{
Method: r.Method,
Url: "https://www.baidu.com" + r.RequestURI,
})
req.PipeFromReq(r).PipeToResponse(w)
})); err != nil {
panic(err)
}
}
評(píng)論
圖片
表情
