Commit 316f35e7 by Li Feifei

format

parent 98b94a73
Pipeline #15630 passed with stages
in 37 seconds
......@@ -2,7 +2,6 @@ package http
import (
"io"
"net/http"
"os"
"time"
......@@ -11,27 +10,30 @@ import (
)
func Get(url string) ([]byte, error) {
return Handle(g.Client().Timeout(30 * time.Second).Get(url))
return handle(g.Client().Timeout(30 * time.Second).Get(url))
}
func Handle(response *ghttp.ClientResponse, err error) ([]byte, error) {
func handle(response *ghttp.ClientResponse, err error) ([]byte, error) {
if err != nil {
return nil, err
}
defer response.Close()
return response.ReadAll(), nil
}
// 下载文件
func Download(file string, path string) error {
g.Log().Async().Infof("Download zip url: %s ", file)
resp, err := http.Get(file)
g.Log().Async().Infof("Download url: %s ", file)
resp, err := g.Client().Get(file)
if err != nil {
return err
}
defer resp.Body.Close()
// 创建一个文件用于保存
out, err := os.Create(path)
if err != nil {
......
......@@ -29,10 +29,10 @@ func NewSessionHttpClient() *SessionHttpClient {
}
func (client *SessionHttpClient) Post(link string, data ...interface{}) ([]byte, error) {
return Handle(client.c.Timeout(10*time.Second).Post(link, data))
return handle(client.c.Timeout(10 * time.Second).Post(link, data))
}
func (client *SessionHttpClient) Get(url string) ([]byte, error) {
return Handle(client.c.Timeout(10 * time.Second).Get(url))
return handle(client.c.Timeout(10 * time.Second).Get(url))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment