Skip to content

Commit

Permalink
[A] fetch get
Browse files Browse the repository at this point in the history
  • Loading branch information
zxysilent committed Aug 5, 2021
1 parent 7713544 commit a8fa0a1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions internal/fetch/fetch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fetch

import (
"encoding/json"
"net/http"
"time"
)

// http 请求用
// 总计超时时间限制5s
var client = http.Client{Timeout: 5 * time.Second}

// Get HTTP 工具类, GET 并解析返回的报文,如果有错误,返回 error
// url 统一资源定位符(uniform resource locator;URL)
// reply 返回值
func Get(url string, reply interface{}) error {
resp, err := client.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
return json.NewDecoder(resp.Body).Decode(reply)
}

0 comments on commit a8fa0a1

Please sign in to comment.