httpclient

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserAgent      = "Zadig REST Client"
	TimeoutSeconds = 10
)

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(url string, rfs ...RequestFunc) (*resty.Response, error)

func IsNotFound added in v1.2.0

func IsNotFound(err error) bool

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 New

func New(cfs ...ClientFunc) *Client

func (*Client) Delete

func (c *Client) Delete(url string, rfs ...RequestFunc) (*resty.Response, error)

func (*Client) Get

func (c *Client) Get(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)

func (*Client) Post

func (c *Client) Post(url string, rfs ...RequestFunc) (*resty.Response, error)

func (*Client) Put

func (c *Client) Put(url string, rfs ...RequestFunc) (*resty.Response, error)

func (*Client) Request

func (c *Client) Request(method, 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 added in v1.9.9

func SetClientHeader(header, value string) ClientFunc

func SetHostURL

func SetHostURL(url string) ClientFunc

func SetIgnoreCodes added in v1.3.0

func SetIgnoreCodes(codes ...int) ClientFunc

func SetProxy

func SetProxy(proxyURL string) ClientFunc

func SetRetryCount added in v1.3.0

func SetRetryCount(count int) ClientFunc

func SetRetryWaitTime added in v1.3.0

func SetRetryWaitTime(waitTime time.Duration) ClientFunc

func SetTLSClientConfig added in v1.4.0

func SetTLSClientConfig(config *tls.Config) ClientFunc

func UnsetTimeout added in v1.3.0

func UnsetTimeout() ClientFunc

type Error

type Error struct {
	Code      int
	ErrStatus StatusReason
	Message   string
	Detail    string
}

func NewErrorFromRestyResponse added in v1.2.0

func NewErrorFromRestyResponse(res *resty.Response) *Error

func NewGenericServerResponse added in v1.2.0

func NewGenericServerResponse(code int, method string, detail string) *Error

NewGenericServerResponse returns a new error for server responses.

func (*Error) Error

func (e *Error) Error() string

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 added in v1.9.9

func SetFormData(data map[string]string) RequestFunc

func SetHeader

func SetHeader(header, value string) RequestFunc

func SetHeaders added in v1.9.9

func SetHeaders(headers map[string]string) RequestFunc

func SetHeadersFromHTTPHeader added in v1.7.0

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 added in v1.2.0

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"

	// StatusReasonUnauthorized means the server can be reached and understood the request, but requires
	// 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"

	// StatusReasonServiceUnavailable means that the request itself was valid,
	// 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 added in v1.2.0

func ReasonForError(err error) StatusReason

Jump to

Keyboard shortcuts

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