![企业微信截图_20240221171200.png](https://static.golangjob.cn/240221/74a3a19210bcd92e0d5baa660a1ab04b.png)
在对接第三方接口时,痛点我就不直说了,经历过的都懂。
所以开发了这个插件,直接生成代码,不仅支持golang还支持更多主流的语言!
# [GITHUB开源地址](https://github.com/2637309949/uhelpers)
写一个简单的DEMO
CURL2GO
```bash
curl 'http://en.wikipedia.org/' \
-H 'Accept-Encoding: gzip, deflate, sdch' \
-H 'Accept-Language: en-US,en;q=0.8' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' \
-H 'Referer: http://www.wikipedia.org/' \
-H 'Connection: keep-alive' --compressed
```
生成效果!
```golang
package main
import (
"fmt"
"io"
"log"
"net/http"
)
func main() {
client := &http.Client{}
req, err := http.NewRequest("GET", "http://en.wikipedia.org/", nil)
if err != nil {
log.Fatal(err)
}
// req.Header.Set("Accept-Encoding", "gzip, deflate, sdch")
req.Header.Set("Accept-Language", "en-US,en;q=0.8")
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36")
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
req.Header.Set("Referer", "http://www.wikipedia.org/")
req.Header.Set("Connection", "keep-alive")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", bodyText)
}
```
有疑问加站长微信联系(非本文作者)
![](https://static.golangjob.cn/static/img/footer.png?imageView2/2/w/280)