rest

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Name is a constant of type string
	Name = "rest"
	// FailureTypePrefix is a constant of type string
	FailureTypePrefix = "http_"
	//DefaultTimeoutBySecond defines the default timeout for http connections
	DefaultTimeoutBySecond = 60 * time.Second
	//DefaultKeepAliveSecond defines the connection time
	DefaultKeepAliveSecond = 60 * time.Second
	//DefaultMaxConnsPerHost defines the maximum number of concurrent connections
	DefaultMaxConnsPerHost = 512
	//SchemaHTTP represents the http schema
	SchemaHTTP = "http"
	//SchemaHTTPS represents the https schema
	SchemaHTTPS = "https"
)

Variables

View Source
var (
	//ErrCanceled means Request is canceled by context management
	ErrCanceled = errors.New("request cancelled")
	//ErrInvalidReq invalid input
	ErrInvalidReq = errors.New("rest consumer call arg is not *rest.Request type")
	//ErrInvalidResp invalid input
	ErrInvalidResp = errors.New("rest consumer response arg is not *rest.Response type")
)

HTTPFailureTypeMap is a variable of type map

Functions

func NewRestClient

func NewRestClient(opts client.Options) client.ProtocolClient

NewRestClient is a function

Types

type Client

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

Client is a struct

func (*Client) Call

func (c *Client) Call(ctx context.Context, addr string, inv *invocation.Invocation, rsp interface{}) error

Call is a method which uses client struct object

func (*Client) Do

func (c *Client) Do(req *Request, resp *Response) (err error)

Do is a method

func (*Client) String

func (c *Client) String() string

type Request

type Request struct {
	Req *http.Request
}

Request is struct

func NewRequest

func NewRequest(method, urlStr string, body ...[]byte) (*Request, error)

NewRequest is a function which creates new request

func (*Request) Close

func (req *Request) Close()

Close is used for closing a request TODO Confirm it's necessary or not

func (*Request) Copy

func (req *Request) Copy() *Request

Copy is method

func (*Request) GetContentType

func (req *Request) GetContentType() string

GetContentType is a method used for getting content-type in a request

func (*Request) GetCookie

func (req *Request) GetCookie(key string) string

GetCookie is a method which gets cookie from a request

func (*Request) GetHeader

func (req *Request) GetHeader(key string) string

GetHeader is a method which gets head from a request

func (*Request) GetMethod

func (req *Request) GetMethod() string

GetMethod is a method

func (*Request) GetRequest

func (req *Request) GetRequest() *http.Request

GetRequest is a method

func (*Request) GetURI

func (req *Request) GetURI() string

GetURI is a method

func (*Request) SetBody

func (req *Request) SetBody(body []byte)

SetBody is a method used for setting body for a request

func (*Request) SetContentType

func (req *Request) SetContentType(ct string)

SetContentType is a method used for setting content-type in a request

func (*Request) SetCookie

func (req *Request) SetCookie(k, v string)

SetCookie set key value in request cookie

func (*Request) SetHeader

func (req *Request) SetHeader(key, value string)

SetHeader is a method used for setting header in a request

func (*Request) SetHeaderCookie

func (req *Request) SetHeaderCookie(key, value string)

SetHeaderCookie is a method used to setting header cookie

func (*Request) SetMethod

func (req *Request) SetMethod(method string)

SetMethod is a method

func (*Request) SetURI

func (req *Request) SetURI(url string)

SetURI sets host for the request.

type Response

type Response struct {
	Resp *http.Response
}

Response is a struct used for handling response

func NewResponse

func NewResponse() *Response

NewResponse is creating the object of response

func (*Response) Close

func (resp *Response) Close()

Close closes the file descriptor TODO Confirm it's necessary or not

func (*Response) GetCookie

func (resp *Response) GetCookie(key string) []byte

GetCookie returns response Cookie.

func (*Response) GetHeader

func (resp *Response) GetHeader() []byte

GetHeader get header from the response TODO Confirm it's necessary or not

func (*Response) GetResponse

func (resp *Response) GetResponse() *http.Response

GetResponse is a method used to get response

func (*Response) GetStatusCode

func (resp *Response) GetStatusCode() int

GetStatusCode returns response status code.

func (*Response) ReadBody

func (resp *Response) ReadBody() []byte

ReadBody read body from the from the response

func (*Response) SetCookie

func (resp *Response) SetCookie(cookie *http.Cookie)

SetCookie sets the cookie.

func (*Response) SetStatusCode

func (resp *Response) SetStatusCode(s int)

SetStatusCode sets the status code

Jump to

Keyboard shortcuts

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