Documentation ¶
Index ¶
- Constants
- func Delete(url string, rfs ...RequestFunc) (*resty.Response, error)
- func Download(url, path string, rfs ...RequestFunc) error
- func Get(url string, rfs ...RequestFunc) (*resty.Response, error)
- func Head(url string, rfs ...RequestFunc) (*resty.Response, error)
- func IsNotFound(err error) bool
- func Options(url string, rfs ...RequestFunc) (*resty.Response, error)
- func Patch(url string, rfs ...RequestFunc) (*resty.Response, error)
- func Post(url string, rfs ...RequestFunc) (*resty.Response, error)
- func Put(url string, rfs ...RequestFunc) (*resty.Response, error)
- type Client
- func (c *Client) Delete(url string, rfs ...RequestFunc) (*resty.Response, error)
- func (c *Client) Get(url string, rfs ...RequestFunc) (*resty.Response, error)
- func (c *Client) Head(url string, rfs ...RequestFunc) (*resty.Response, error)
- func (c *Client) Options(url string, rfs ...RequestFunc) (*resty.Response, error)
- func (c *Client) Patch(url string, rfs ...RequestFunc) (*resty.Response, error)
- func (c *Client) Post(url string, rfs ...RequestFunc) (*resty.Response, error)
- func (c *Client) Put(url string, rfs ...RequestFunc) (*resty.Response, error)
- func (c *Client) Request(method, url string, rfs ...RequestFunc) (*resty.Response, error)
- type ClientFunc
- func SetAuthScheme(scheme string) ClientFunc
- func SetAuthToken(token string) ClientFunc
- func SetBaseURI(uri string) ClientFunc
- func SetBasicAuth(username, password string) ClientFunc
- func SetClientHeader(header, value string) ClientFunc
- func SetHostURL(url string) ClientFunc
- func SetIgnoreCodes(codes ...int) ClientFunc
- func SetProxy(proxyURL string) ClientFunc
- func SetRetryCount(count int) ClientFunc
- func SetRetryWaitTime(waitTime time.Duration) ClientFunc
- func SetTLSClientConfig(config *tls.Config) ClientFunc
- func UnsetTimeout() ClientFunc
- type Error
- type RequestFunc
- func ForceContentType(contentType string) RequestFunc
- func SetBody(body interface{}) RequestFunc
- func SetFormData(data map[string]string) RequestFunc
- func SetHeader(header, value string) RequestFunc
- func SetHeaders(headers map[string]string) RequestFunc
- func SetHeadersFromHTTPHeader(header http.Header) RequestFunc
- func SetQueryParam(param, value string) RequestFunc
- func SetQueryParams(params map[string]string) RequestFunc
- func SetQueryParamsFromValues(params url.Values) RequestFunc
- func SetResult(res interface{}) RequestFunc
- type StatusReason
Constants ¶
View Source
const ( UserAgent = "Zadig Agent REST Client" TimeoutSeconds = 60 )
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
func Delete(url string, rfs ...RequestFunc) (*resty.Response, error)
func Download ¶
func Download(url, path string, rfs ...RequestFunc) error
Download retrieves content from the given url and write it to path.
func Get ¶
func Get(url string, rfs ...RequestFunc) (*resty.Response, error)
func Head ¶
func Head(url string, rfs ...RequestFunc) (*resty.Response, error)
func IsNotFound ¶
func Options ¶
func Options(url string, rfs ...RequestFunc) (*resty.Response, error)
func Patch ¶
func Patch(url string, rfs ...RequestFunc) (*resty.Response, error)
func Post ¶
func Post(url string, rfs ...RequestFunc) (*resty.Response, error)
func Put ¶
func Put(url string, rfs ...RequestFunc) (*resty.Response, error)
Types ¶
type Client ¶
type Client struct { *resty.Client Host string // Host is the fully qualified domain name of the system, or an IP Address. Port and protocol are required if necessary. BaseURI string // BaseURI is the base uri for every request, starting with a slash, for example: /api/v1 IgnoreCodes sets.Int // IgnoreCodes ignores some code to be returned as an error. }
func (*Client) Delete ¶
func (c *Client) Delete(url string, rfs ...RequestFunc) (*resty.Response, error)
func (*Client) Head ¶
func (c *Client) Head(url string, rfs ...RequestFunc) (*resty.Response, error)
func (*Client) Options ¶
func (c *Client) Options(url string, rfs ...RequestFunc) (*resty.Response, error)
func (*Client) Patch ¶
func (c *Client) Patch(url string, rfs ...RequestFunc) (*resty.Response, error)
type ClientFunc ¶
type ClientFunc func(*Client)
func SetAuthScheme ¶
func SetAuthScheme(scheme string) ClientFunc
func SetAuthToken ¶
func SetAuthToken(token string) ClientFunc
func SetBaseURI ¶
func SetBaseURI(uri string) ClientFunc
func SetBasicAuth ¶
func SetBasicAuth(username, password string) ClientFunc
func SetClientHeader ¶
func SetClientHeader(header, value string) ClientFunc
func SetHostURL ¶
func SetHostURL(url string) ClientFunc
func SetIgnoreCodes ¶
func SetIgnoreCodes(codes ...int) ClientFunc
func SetProxy ¶
func SetProxy(proxyURL string) ClientFunc
func SetRetryCount ¶
func SetRetryCount(count int) ClientFunc
func SetRetryWaitTime ¶
func SetRetryWaitTime(waitTime time.Duration) ClientFunc
func SetTLSClientConfig ¶
func SetTLSClientConfig(config *tls.Config) ClientFunc
func UnsetTimeout ¶
func UnsetTimeout() ClientFunc
type Error ¶
type Error struct { Code int ErrStatus StatusReason Message string Detail string }
func NewErrorFromRestyResponse ¶
func NewErrorFromRestyResponse(res *resty.Response) *Error
func NewGenericServerResponse ¶
NewGenericServerResponse returns a new error for server responses.
func (*Error) Status ¶
func (e *Error) Status() StatusReason
type RequestFunc ¶
type RequestFunc func(request *resty.Request)
func ForceContentType ¶
func ForceContentType(contentType string) RequestFunc
func SetBody ¶
func SetBody(body interface{}) RequestFunc
func SetFormData ¶
func SetFormData(data map[string]string) RequestFunc
func SetHeader ¶
func SetHeader(header, value string) RequestFunc
func SetHeaders ¶
func SetHeaders(headers map[string]string) RequestFunc
func SetHeadersFromHTTPHeader ¶
func SetHeadersFromHTTPHeader(header http.Header) RequestFunc
func SetQueryParam ¶
func SetQueryParam(param, value string) RequestFunc
func SetQueryParams ¶
func SetQueryParams(params map[string]string) RequestFunc
func SetQueryParamsFromValues ¶
func SetQueryParamsFromValues(params url.Values) RequestFunc
func SetResult ¶
func SetResult(res interface{}) RequestFunc
type StatusReason ¶
type StatusReason string
StatusReason is an enumeration of possible failure causes. Each StatusReason must map to a single HTTP status code, but multiple reasons may map to the same HTTP status code.
const ( // StatusReasonUnknown means the server has declined to indicate a specific reason. StatusReasonUnknown StatusReason = "" // StatusReasonBadRequest means that the request itself was invalid, because the request // doesn't make any sense, for example deleting a read-only object. This is different than // StatusReasonInvalid above which indicates that the API call could possibly succeed, but the // data was invalid. API calls that return BadRequest can never succeed. // Status code 400 StatusReasonBadRequest StatusReason = "BadRequest" // the user to present appropriate authorization credentials (identified by the WWW-Authenticate header) // in order for the action to be completed. If the user has specified credentials on the request, the // server considers them insufficient. // Status code 401 StatusReasonUnauthorized StatusReason = "Unauthorized" // StatusReasonForbidden means the server can be reached and understood the request, but refuses // to take any further action. It is the result of the server being configured to deny access for some reason // to the requested resource by the client. // Status code 403 StatusReasonForbidden StatusReason = "Forbidden" // StatusReasonNotFound means one or more resources required for this operation // could not be found. // Status code 404 StatusReasonNotFound StatusReason = "NotFound" // StatusReasonMethodNotAllowed means that the action the client attempted to perform on the // resource was not supported by the code - for instance, attempting to delete a resource that // can only be created. API calls that return MethodNotAllowed can never succeed. // Status code 405 StatusReasonMethodNotAllowed StatusReason = "MethodNotAllowed" // StatusReasonNotAcceptable means that the accept types indicated by the client were not acceptable // to the server - for instance, attempting to receive protobuf for a resource that supports only json and yaml. // API calls that return NotAcceptable can never succeed. // Status code 406 StatusReasonNotAcceptable StatusReason = "NotAcceptable" // StatusReasonAlreadyExists means the resource you are creating already exists. // Status code 409 StatusReasonAlreadyExists StatusReason = "AlreadyExists" // StatusReasonConflict means the requested operation cannot be completed // due to a conflict in the operation. The client may need to alter the // request. Each resource may define custom details that indicate the // nature of the conflict. // Status code 409 StatusReasonConflict StatusReason = "Conflict" // StatusReasonGone means the item is no longer available at the server and no // forwarding address is known. // Status code 410 StatusReasonGone StatusReason = "Gone" // StatusReasonUnsupportedMediaType means that the content type sent by the client is not acceptable // to the server - for instance, attempting to send protobuf for a resource that supports only json and yaml. // API calls that return UnsupportedMediaType can never succeed. // Status code 415 StatusReasonUnsupportedMediaType StatusReason = "UnsupportedMediaType" // StatusReasonInvalid means the requested create or update operation cannot be // completed due to invalid data provided as part of the request. The client may // need to alter the request. // Status code 422 StatusReasonInvalid StatusReason = "Invalid" // StatusReasonTooManyRequests means the server experienced too many requests within a // given window and that the client must wait to perform the action again. A client may // always retry the request that led to this error, although the client should wait at least // the number of seconds specified by the retryAfterSeconds field. // Status code 429 StatusReasonTooManyRequests StatusReason = "TooManyRequests" // StatusReasonInternalError indicates that an internal error occurred, it is unexpected // and the outcome of the call is unknown. // Status code 500 StatusReasonInternalError StatusReason = "InternalError" // but the requested service is unavailable at this time. // Retrying the request after some time might succeed. // Status code 503 StatusReasonServiceUnavailable StatusReason = "ServiceUnavailable" )
func ReasonForError ¶
func ReasonForError(err error) StatusReason
Click to show internal directories.
Click to hide internal directories.