rest

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRESTError

func IsRESTError(err error) bool

IsRESTError checks if an error is generated from this package.

Types

type Client

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

Client implements builder pattern for http client.

func NewClient

func NewClient(cfg *Config) (*Client, error)

NewClient creates a client.

func (*Client) Request

func (c *Client) Request(method string, code int, url string) *Request

Request creates an request with specific method and url path. The code is only for checking if status code of response is right.

type Config

type Config struct {
	// Scheme is http scheme. It can be "http" or "https".
	Scheme string
	// Host must be a host string, a host:port or a URL to a server.
	Host string
	// Executor is used to execute http requests.
	// If it is empty, http.DefaultClient is used.
	Executor RequestExecutor
}

Config is rest client config.

func (*Config) Complete

func (c *Config) Complete() error

Complete completes the config and returns an error if something is wrong.

func (*Config) DeepCopy

func (c *Config) DeepCopy() *Config

DeepCopy returns a new config copied from the current one.

type Request

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

Request describes a http request.

func (*Request) Body

func (r *Request) Body(contentType string, value interface{}) *Request

Body sets body parameter.

func (*Request) Data

func (r *Request) Data(value interface{}) *Request

Data sets body result. value must be a pointer.

func (*Request) Do

func (r *Request) Do(ctx context.Context) error

Do executes the request.

func (*Request) File

func (r *Request) File(name string, file interface{}) *Request

File sets file parameter.

func (*Request) Form

func (r *Request) Form(name string, values ...interface{}) *Request

Form sets form parameter.

func (*Request) Header

func (r *Request) Header(name string, values ...interface{}) *Request

Header sets header parameter.

func (*Request) Meta

func (r *Request) Meta(value *map[string]string) *Request

Meta sets header result.

func (*Request) Path

func (r *Request) Path(name string, value interface{}) *Request

Path sets path parameter.

func (*Request) Query

func (r *Request) Query(name string, values ...interface{}) *Request

Query sets query parameter.

type RequestExecutor

type RequestExecutor interface {
	Do(req *http.Request) (*http.Response, error)
}

RequestExecutor implements a http client.

Jump to

Keyboard shortcuts

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