@@ -11,14 +11,13 @@ import (
1111 "github.com/zssky/log"
1212)
1313
14- //Client 对http client简单封装.
15- type Client struct {
14+ type httpClient struct {
1615 hc http.Client
1716}
1817
1918//NewClient 创建一个带超时控制的http client.
20- func NewClient (timeout time.Duration ) Client {
21- return Client {
19+ func New (timeout time.Duration ) httpClient {
20+ return httpClient {
2221 hc : http.Client {
2322 Transport : & http.Transport {
2423 Dial : func (netw , addr string ) (net.Conn , error ) {
@@ -39,7 +38,7 @@ func NewClient(timeout time.Duration) Client {
3938 }
4039}
4140
42- func (c Client ) do (method , url string , headers map [string ]string , body * bytes.Buffer ) ([]byte , int , error ) {
41+ func (c httpClient ) do (method , url string , headers map [string ]string , body * bytes.Buffer ) ([]byte , int , error ) {
4342 var req * http.Request
4443 var err error
4544
@@ -72,22 +71,18 @@ func (c Client) do(method, url string, headers map[string]string, body *bytes.Bu
7271 return data , resp .StatusCode , nil
7372}
7473
75- //Get get 请求...
76- func (c Client ) Get (url string , headers map [string ]string , body * bytes.Buffer ) ([]byte , int , error ) {
74+ func (c httpClient ) Get (url string , headers map [string ]string , body * bytes.Buffer ) ([]byte , int , error ) {
7775 return c .do ("GET" , url , headers , body )
7876}
7977
80- //POST post 请求.
81- func (c Client ) POST (url string , headers map [string ]string , body * bytes.Buffer ) ([]byte , int , error ) {
78+ func (c httpClient ) POST (url string , headers map [string ]string , body * bytes.Buffer ) ([]byte , int , error ) {
8279 return c .do ("POST" , url , headers , body )
8380}
8481
85- //PUT put 请求.
86- func (c Client ) PUT (url string , headers map [string ]string , body * bytes.Buffer ) ([]byte , int , error ) {
82+ func (c httpClient ) PUT (url string , headers map [string ]string , body * bytes.Buffer ) ([]byte , int , error ) {
8783 return c .do ("PUT" , url , headers , body )
8884}
8985
90- //DELETE delete 请求.
91- func (c Client ) DELETE (url string , headers map [string ]string , body * bytes.Buffer ) ([]byte , int , error ) {
86+ func (c httpClient ) DELETE (url string , headers map [string ]string , body * bytes.Buffer ) ([]byte , int , error ) {
9287 return c .do ("DELETE" , url , headers , body )
9388}
0 commit comments