http

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package http is an implementation of http protocol

Index

Constants

This section is empty.

Variables

View Source
var DefaultHeaders = map[string]string{
	"Content-Type": "application/x-www-form-urlencoded",
}

DefaultHeaders defined default http headers

View Source
var DefaultTimeout = 30 * time.Second

DefaultTimeout is the default timeout of each request

Functions

This section is empty.

Types

type Client added in v0.6.7

type Client interface {
	Send(*HttpRequest) (*HttpResponse, error)
}

Client is the interface of http client

type HttpClient

type HttpClient struct {
}

HttpClient used to send a real request via http to server

func NewHttpClient

func NewHttpClient() HttpClient

NewHttpClient will create a new HttpClient instance

func (*HttpClient) Send

func (c *HttpClient) Send(req *HttpRequest) (*HttpResponse, error)

Send will send a real http request to remote server

type HttpRequest

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

HttpRequest is the internal http request of sdk, don't use it at your code

func NewHttpRequest

func NewHttpRequest() HttpRequest

NewHttpRequest will create a http request

func (*HttpRequest) BuildQueryString

func (h *HttpRequest) BuildQueryString() (string, error)

BuildQueryString will return the query string of this request, it will also append key-value of query map after existed query string

func (*HttpRequest) GetHeaderMap

func (h *HttpRequest) GetHeaderMap() map[string]string

GetHeaderMap wiil get all of header as a map

func (*HttpRequest) GetMethod

func (h *HttpRequest) GetMethod() string

GetMethod will get request url value

func (*HttpRequest) GetQuery added in v0.6.7

func (h *HttpRequest) GetQuery(k string) string

GetQuery will get value by key from map

func (*HttpRequest) GetQueryMap

func (h *HttpRequest) GetQueryMap() map[string]string

GetQueryMap will get all of query as a map

func (*HttpRequest) GetRequestBody

func (h *HttpRequest) GetRequestBody() []byte

GetRequestBody will get origin http request ("net/http")

func (*HttpRequest) GetTimeout

func (h *HttpRequest) GetTimeout() time.Duration

GetTimeout will get timeout of current request

func (*HttpRequest) GetURL

func (h *HttpRequest) GetURL() string

GetURL will get request url value

func (*HttpRequest) SetHeader

func (h *HttpRequest) SetHeader(k, v string) error

SetHeader will set http header of current request

func (*HttpRequest) SetMethod

func (h *HttpRequest) SetMethod(val string) error

SetMethod will set method of current request

func (*HttpRequest) SetQuery

func (h *HttpRequest) SetQuery(k, v string) error

SetQuery will store key-value data into query map

func (*HttpRequest) SetQueryString

func (h *HttpRequest) SetQueryString(val string) error

SetQueryString will set query map by query string, it also save as query string attribute to keep query ordered.

func (*HttpRequest) SetRequestBody

func (h *HttpRequest) SetRequestBody(val []byte) error

SetRequestBody will set http body of current request

func (*HttpRequest) SetTimeout

func (h *HttpRequest) SetTimeout(val time.Duration) error

SetTimeout will set timeout of current request

func (*HttpRequest) SetURL

func (h *HttpRequest) SetURL(val string) error

SetURL will set url into request

func (*HttpRequest) String

func (h *HttpRequest) String() string

type HttpResponse

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

HttpResponse is a simple wrapper of "net/http" response

func NewHttpResponse

func NewHttpResponse() *HttpResponse

NewHttpResponse will create a new response of http request

func (*HttpResponse) GetBody

func (h *HttpResponse) GetBody() []byte

GetBody will get body from from sdk http request

func (*HttpResponse) GetStatusCode

func (h *HttpResponse) GetStatusCode() int

GetStatusCode will return status code of origin http response

func (*HttpResponse) SetBody added in v0.6.8

func (h *HttpResponse) SetBody(body []byte) error

SetBody will set body into http response it usually used for restore the body already read from an stream it will also cause extra memory usage

func (*HttpResponse) SetStatusCode added in v0.6.8

func (h *HttpResponse) SetStatusCode(code int)

SetStatusCode will return status code of origin http response

type StatusError

type StatusError struct {
	StatusCode int
	Message    string
}

StatusError is the error for http status code >= 400

func NewStatusError

func NewStatusError(code int, message string) StatusError

NewStatusError will create a new status error

func (StatusError) Error

func (e StatusError) Error() string

Jump to

Keyboard shortcuts

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