Skip to content

Commit

Permalink
Merge pull request #1 from dearcode/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
c-wind authored Sep 19, 2017
2 parents c9ee189 + 5e4ee53 commit 43df0be
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 241 deletions.
200 changes: 0 additions & 200 deletions handler/handler.go

This file was deleted.

23 changes: 9 additions & 14 deletions http_client/client.go → http/client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package httpClient
package client

import (
"bytes"
Expand All @@ -11,14 +11,13 @@ import (
"github.com/zssky/log"
)

//Client 对http client简单封装.
type Client struct {
type httpClient struct {
hc http.Client
}

//NewClient 创建一个带超时控制的http client.
func NewClient(timeout time.Duration) Client {
return Client{
func New(timeout time.Duration) httpClient {
return httpClient{
hc: http.Client{
Transport: &http.Transport{
Dial: func(netw, addr string) (net.Conn, error) {
Expand All @@ -39,7 +38,7 @@ func NewClient(timeout time.Duration) Client {
}
}

func (c Client) do(method, url string, headers map[string]string, body *bytes.Buffer) ([]byte, int, error) {
func (c httpClient) do(method, url string, headers map[string]string, body *bytes.Buffer) ([]byte, int, error) {
var req *http.Request
var err error

Expand Down Expand Up @@ -72,22 +71,18 @@ func (c Client) do(method, url string, headers map[string]string, body *bytes.Bu
return data, resp.StatusCode, nil
}

//Get get 请求...
func (c Client) Get(url string, headers map[string]string, body *bytes.Buffer) ([]byte, int, error) {
func (c httpClient) Get(url string, headers map[string]string, body *bytes.Buffer) ([]byte, int, error) {
return c.do("GET", url, headers, body)
}

//POST post 请求.
func (c Client) POST(url string, headers map[string]string, body *bytes.Buffer) ([]byte, int, error) {
func (c httpClient) POST(url string, headers map[string]string, body *bytes.Buffer) ([]byte, int, error) {
return c.do("POST", url, headers, body)
}

//PUT put 请求.
func (c Client) PUT(url string, headers map[string]string, body *bytes.Buffer) ([]byte, int, error) {
func (c httpClient) PUT(url string, headers map[string]string, body *bytes.Buffer) ([]byte, int, error) {
return c.do("PUT", url, headers, body)
}

//DELETE delete 请求.
func (c Client) DELETE(url string, headers map[string]string, body *bytes.Buffer) ([]byte, int, error) {
func (c httpClient) DELETE(url string, headers map[string]string, body *bytes.Buffer) ([]byte, int, error) {
return c.do("DELETE", url, headers, body)
}
2 changes: 1 addition & 1 deletion handler/common.go → http/server/common.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package handler
package server

import (
"encoding/json"
Expand Down
Loading

0 comments on commit 43df0be

Please sign in to comment.