Documentation ¶
Index ¶
- Constants
- Variables
- func NewRestClient(opts client.Options) client.ProtocolClient
- type Client
- type Request
- func (req *Request) Close()
- func (req *Request) Copy() *Request
- func (req *Request) GetContentType() string
- func (req *Request) GetCookie(key string) string
- func (req *Request) GetHeader(key string) string
- func (req *Request) GetMethod() string
- func (req *Request) GetRequest() *http.Request
- func (req *Request) GetURI() string
- func (req *Request) SetBody(body []byte)
- func (req *Request) SetContentType(ct string)
- func (req *Request) SetCookie(k, v string)
- func (req *Request) SetHeader(key, value string)
- func (req *Request) SetHeaderCookie(key, value string)
- func (req *Request) SetMethod(method string)
- func (req *Request) SetURI(url string)
- type Response
- func (resp *Response) Close()
- func (resp *Response) GetCookie(key string) []byte
- func (resp *Response) GetHeader() []byte
- func (resp *Response) GetResponse() *http.Response
- func (resp *Response) GetStatusCode() int
- func (resp *Response) ReadBody() []byte
- func (resp *Response) SetCookie(cookie *http.Cookie)
- func (resp *Response) SetStatusCode(s int)
Constants ¶
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 ¶
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") )
var HTTPFailureTypeMap = map[string]bool{ FailureTypePrefix + strconv.Itoa(http.StatusInternalServerError): true, FailureTypePrefix + strconv.Itoa(http.StatusBadGateway): true, FailureTypePrefix + strconv.Itoa(http.StatusServiceUnavailable): true, FailureTypePrefix + strconv.Itoa(http.StatusGatewayTimeout): true, FailureTypePrefix + strconv.Itoa(http.StatusTooManyRequests): true, }
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
type Request ¶
Request is struct
func NewRequest ¶
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) GetContentType ¶
GetContentType is a method used for getting content-type in a request
func (*Request) SetContentType ¶
SetContentType is a method used for setting content-type in a request
func (*Request) SetHeaderCookie ¶
SetHeaderCookie is a method used to setting header cookie
type Response ¶
Response is a struct used for handling response
func (*Response) Close ¶
func (resp *Response) Close()
Close closes the file descriptor TODO Confirm it's necessary or not
func (*Response) GetHeader ¶
GetHeader get header from the response TODO Confirm it's necessary or not
func (*Response) GetResponse ¶
GetResponse is a method used to get response
func (*Response) GetStatusCode ¶
GetStatusCode returns response status code.
func (*Response) SetStatusCode ¶
SetStatusCode sets the status code