common

package
v0.0.0-...-3dc91f5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2015 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CHARSET                    = "UTF-8"
	CONTENT_TYPE_JSON          = "application/json"
	DEFAULT_CONNECTION_TIMEOUT = 20 //seconds
	DEFAULT_SOCKET_TIMEOUT     = 30 // seconds
)

Variables

This section is empty.

Functions

func TimeoutDialer

func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)

TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.

Types

type ErrorInfo

type ErrorInfo struct {
	Message string `json:message`
	Code    int    `json:code`
}

type HttpRequest

type HttpRequest struct {
	// contains filtered or unexported fields
}

HttpRequest provides more useful methods for requesting one url than http.Request.

func Get

func Get(url string) *HttpRequest

Get returns *HttpRequest with GET method.

func Post

func Post(url string) *HttpRequest

Post returns *HttpRequest with POST method.

func (*HttpRequest) Body

func (b *HttpRequest) Body(data interface{}) *HttpRequest

Body adds request raw body. it supports string and []byte.

func (*HttpRequest) Bytes

func (b *HttpRequest) Bytes() ([]byte, error)

Bytes returns the body []byte in response. it calls Response inner.

func (*HttpRequest) Header

func (b *HttpRequest) Header(key, value string) *HttpRequest

Header add header item string in request.

func (*HttpRequest) Param

func (b *HttpRequest) Param(key, value string) *HttpRequest

Param adds query param in to request. params build query string as ?key1=value1&key2=value2...

func (*HttpRequest) Response

func (b *HttpRequest) Response() (*http.Response, error)

Response executes request client gets response mannually.

func (*HttpRequest) SetCookie

func (b *HttpRequest) SetCookie(cookie *http.Cookie) *HttpRequest

SetCookie add cookie into request.

func (*HttpRequest) SetProtocolVersion

func (b *HttpRequest) SetProtocolVersion(vers string) *HttpRequest

Set the protocol version for incoming requests. Client requests always use HTTP/1.1.

func (*HttpRequest) SetProxy

func (b *HttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *HttpRequest

Set http proxy example:

func(req *http.Request) (*url.URL, error) {
	u, _ := url.ParseRequestURI("http://127.0.0.1:8118")
	return u, nil
}

func (*HttpRequest) SetTLSClientConfig

func (b *HttpRequest) SetTLSClientConfig(config *tls.Config) *HttpRequest

SetTLSClientConfig sets tls connection configurations if visiting https url.

func (*HttpRequest) SetTimeout

func (b *HttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *HttpRequest

SetTimeout sets connect time out and read-write time out for Request.

func (*HttpRequest) SetTransport

func (b *HttpRequest) SetTransport(transport http.RoundTripper) *HttpRequest

Set transport to

func (*HttpRequest) String

func (b *HttpRequest) String() (string, error)

String returns the body string in response. it calls Response inner.

func (*HttpRequest) ToFile

func (b *HttpRequest) ToFile(filename string) error

ToFile saves the body data in response to one file. it calls Response inner.

func (*HttpRequest) ToJson

func (b *HttpRequest) ToJson(v interface{}) error

ToJson returns the map that marshals from the body bytes as json in response . it calls Response inner.

func (*HttpRequest) ToXML

func (b *HttpRequest) ToXML(v interface{}) error

ToXml returns the map that marshals from the body bytes as xml in response . it calls Response inner.

type RetData

type RetData struct {
	Sendno string `json:sendno`
	MsgID  string `json:msg_id`
	Error  ErrorInfo
}

func SendPostBytes

func SendPostBytes(url string, content []byte, authCode string) (ret *RetData, err error)

func SendPostString

func SendPostString(url, content, authCode string) (ret *RetData, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL