httputils

package
Version: v0.0.0-...-39cffea Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHTTPClient = func() *http.Client {
	return &http.Client{
		Transport: &http.Transport{

			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true,
			},
		},
	}
}()

DefaultHTTPClient will return a default configured http client

Functions

func NewRequest

func NewRequest(ctx context.Context, method string, url string, headers map[string]string, query url.Values, body io.Reader) (*http.Request, error)

NewRequest will create a http request with the specified data

func PackURL

func PackURL(addr string, values url.Values) (string, error)

PackURL will pack the url and the query

func PackURLPath

func PackURLPath(tpl string, args map[string]string) string

PackURLPath will pack the url with a url template and args

Types

type DebugLevel

type DebugLevel int

DebugLevel of the debug logs

const (
	Debug0 DebugLevel = 0
	Debug1 DebugLevel = 1
	Debug2 DebugLevel = 2
)

Prededfined debuglog level

type Response

type Response struct {
	Status     int
	Header     http.Header
	Body       []byte
	BodyStream io.ReadCloser
}

Response is a collection of the response data

func ClientDo

func ClientDo(client *http.Client, req *http.Request, streamResp ...bool) (*Response, error)

ClientDo will excute the request with a specific http client

func Delete

func Delete(ctx context.Context, url string, headers map[string]string, query url.Values) (*Response, error)

Delete will delete remote resource

func Do

func Do(req *http.Request) (*Response, error)

Do will excute the request with the default http client

func Get

func Get(ctx context.Context, url string, headers map[string]string, query url.Values) (*Response, error)

Get will get remote data with custom headers

func Patch

func Patch(ctx context.Context, url string, headers map[string]string, query url.Values, body io.Reader) (*Response, error)

Patch will partially update a remote resource

func Post

func Post(ctx context.Context, url string, headers map[string]string, query url.Values, body io.Reader) (*Response, error)

Post will create remote resource

func PostForm

func PostForm(ctx context.Context, url string, form url.Values) (*Response, error)

PostForm will create remote resource with x-www-form-urlencoded format data

func Put

func Put(ctx context.Context, url string, headers map[string]string, query url.Values, body io.Reader) (*Response, error)

Put will update a remote resource

type RestCli

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

RestCli represents a restful http request

func NewRestCli

func NewRestCli() *RestCli

NewRestCli will create a new RestCli object

func (*RestCli) Body

func (rest *RestCli) Body(body io.Reader) *RestCli

Body will set body for the rest request

func (*RestCli) ClearHeader

func (rest *RestCli) ClearHeader(header string) *RestCli

ClearHeader will clear a header from the rest request

func (*RestCli) ClearQuery

func (rest *RestCli) ClearQuery(query string) *RestCli

ClearQuery will clear a query from the rest request

func (*RestCli) Client

func (rest *RestCli) Client(cli *http.Client) *RestCli

Client will set a user specified http client for the rest request

func (*RestCli) Context

func (rest *RestCli) Context(ctx context.Context) *RestCli

Context will set a user specified context for the rest request

func (*RestCli) Debug

func (rest *RestCli) Debug(level ...DebugLevel) *RestCli

Debug will turn on or turn off the debug process

func (*RestCli) Delete

func (rest *RestCli) Delete() *RestCli

Delete will delete the rest request

func (*RestCli) Do

func (rest *RestCli) Do() (*Response, error)

Do will send the rest request to remote api and process the resp

func (*RestCli) FormData

func (rest *RestCli) FormData(data url.Values) *RestCli

FormData will set the body object for the form request

func (*RestCli) Get

func (rest *RestCli) Get() *RestCli

Get will get the rest request

func (*RestCli) Host

func (rest *RestCli) Host(host string) *RestCli

Host will set the remote host address for the rest request

func (*RestCli) Into

func (rest *RestCli) Into(status string, resp interface{}) *RestCli

Into will store the ok response of the rest request

func (*RestCli) Method

func (rest *RestCli) Method(method string) *RestCli

Method will set the http method for the rest request

func (*RestCli) Object

func (rest *RestCli) Object(body interface{}) *RestCli

Object will set the body object for the rest request

func (*RestCli) Patch

func (rest *RestCli) Patch() *RestCli

Patch will post the rest request

func (*RestCli) Post

func (rest *RestCli) Post() *RestCli

Post will post the rest request

func (*RestCli) Put

func (rest *RestCli) Put() *RestCli

Put will put the rest request

func (*RestCli) ResourcePath

func (rest *RestCli) ResourcePath(resource string) *RestCli

ResourcePath will set the remote api Resource for the rest request

func (*RestCli) SetHeader

func (rest *RestCli) SetHeader(header, value string) *RestCli

SetHeader will set a header pair for the rest request

func (*RestCli) SetQuery

func (rest *RestCli) SetQuery(query string, value ...string) *RestCli

SetQuery will set a query for the rest request

func (*RestCli) Stream

func (rest *RestCli) Stream() *RestCli

Stream will turn on or turn off the debug process

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL