core

package
v0.0.0-...-dad8e04 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyURI                = errors.New("uri cannot be empty")
	ErrNilPathParameters       = errors.New("uri template parameters cannot be nil")
	ErrNilQueryParamters       = errors.New("uri query parameters cannot be nil")
	ErrMissingBasePathParam    = errors.New("pathParameters must contain a value for \"baseurl\" for the URL to be built")
	ErrMissingBasePathTemplate = errors.New("template must contain a placeholder for \"{+baseurl}\" for the URL to be built")
	ErrInvalidHeaderType       = errors.New("headers must be a pointer or an http.Header")
	ErrEmptyRawURL             = errors.New("empty raw URL")
	ErrMissingSchema           = errors.New("URL is missing schema")
	ErrNilResponse             = errors.New("Response is nil")
	ErrNilResponseBody         = errors.New("response body is nil")
	ErrNilSource               = errors.New("source is nil")
	ErrNilCredential           = errors.New("credential is nil")

	//Page Iterator
	ErrNilClient         = errors.New("client can't be nil")
	ErrNilResult         = errors.New("result property missing in response object")
	ErrWrongResponseType = errors.New("incorrect Response Type")
	ErrParsing           = errors.New("parsing nextLink url failed")
	ErrNilCallback       = errors.New("callback can't be nil")

	//Authorization Provider
	ErrNilRequest = errors.New("request can't be nil")
)

Functions

func FromJSON

func FromJSON[T any](response *http.Response, v *T) error

func IsNil

func IsNil(a interface{}) bool

IsNil checks if a value is nil or a nil interface

func ParseResponse

func ParseResponse[T Response](response *http.Response, value *T) error

ParseResponse[T] parses the HTTP Response to the provided type

func ResetCalls

func ResetCalls(calls ...*mock.Call)

func ToQueryMap

func ToQueryMap(source interface{}) (map[string]string, error)

ToQueryMap converts a struct to query parameter map

func WithMethod

func WithMethod(method HttpMethod) requestInformationOption

func WithPathParams

func WithPathParams(pathParameters map[string]string) requestInformationOption

func WithURITemplate

func WithURITemplate(template string) requestInformationOption

Types

type Client2

type Client2 interface {
	Send(RequestInformation, ErrorMapping) (*http.Response, error)
	SendWithContext(context.Context, RequestInformation, ErrorMapping) (*http.Response, error)
	GetBaseURL() string
}

type ErrorMapping

type ErrorMapping interface {
	Set(code, err string)
	Len() int
	Get(code int) (string, bool)
}

type HttpMethod

type HttpMethod int //nolint:stylecheck

Represents the HTTP method used by a request.

const (
	// The HTTP GET method.
	GET HttpMethod = iota
	// The HTTP POST method.
	POST
	// The HTTP PATCH method.
	PATCH
	// The HTTP DELETE method.
	DELETE
	// The HTTP OPTIONS method.
	OPTIONS
	// The HTTP CONNECT method.
	CONNECT
	// The HTTP PUT method.
	PUT
	// The HTTP TRACE method.
	TRACE
	// The HTTP HEAD method.
	HEAD
)

func (HttpMethod) String

func (m HttpMethod) String() string

String returns the string representation of the HTTP method.

type RequestBuilder

type RequestBuilder interface {
	SendDelete2(config *RequestConfiguration) error
	SendGet2(config *RequestConfiguration) error
	SendPost3(config *RequestConfiguration) error
	SendPut2(config *RequestConfiguration) error
	ToDeleteRequestInformation(params interface{}) (*RequestInformation, error)
	ToDeleteRequestInformation2(config *RequestConfiguration) (*RequestInformation, error)
	ToGetRequestInformation(params interface{}) (*RequestInformation, error)
	ToGetRequestInformation2(config *RequestConfiguration) (*RequestInformation, error)
	ToHeadRequestInformation() (*RequestInformation, error)
	ToPostRequestInformation(data map[string]string, params interface{}) (*RequestInformation, error)
	ToPostRequestInformation2(data interface{}, params interface{}) (*RequestInformation, error)
	ToPostRequestInformation3(config interface{}) (*RequestInformation, error)
	ToPutRequestInformation(data map[string]string, params interface{}) (*RequestInformation, error)
	ToPutRequestInformation2(config interface{}) (*RequestInformation, error)
	ToRequestInformation(method HttpMethod, data map[string]string, params interface{}) (*RequestInformation, error)
	ToRequestInformation2(method HttpMethod, rawData interface{}, params interface{}) (*RequestInformation, error)
	ToRequestInformation3(method HttpMethod, config *interface{}) (*RequestInformation, error)
}

type RequestBuilder2

type RequestBuilder2 interface {
	ToRequestInformation(method HttpMethod, config *RequestConfiguration) (RequestInformation, error)
	GetPathParameters() map[string]string
	GetClient() Client2
	GetURLTemplate() string
	Send(ctx context.Context, method HttpMethod, opts ...RequestConfigurationOption) (interface{}, error)
}

func NewRequestBuilder2

func NewRequestBuilder2(client Client2, urlTemplate string, pathParameters map[string]string) RequestBuilder2

type RequestConfiguration

type RequestConfiguration struct {
	Header          interface{}
	QueryParameters interface{}
	Data            interface{}
	ErrorMapping    ErrorMapping
	Response        Response
}

func ApplyOptions

func ApplyOptions(opts ...RequestConfigurationOption) *RequestConfiguration

ApplyOptions applies the given options to a RequestConfiguration.

type RequestConfigurationOption

type RequestConfigurationOption func(*RequestConfiguration)

RequestConfigurationOption the functional option type for configuring requests.

func WithData

func WithData(data interface{}) RequestConfigurationOption

WithData sets the data for the request.

func WithErrorMapping

func WithErrorMapping(errorMapping ErrorMapping) RequestConfigurationOption

WithErrorMapping sets the error mapping for the request.

func WithHeader

func WithHeader[T any](header T) RequestConfigurationOption

WithHeader sets the header for the request.

func WithQueryParameters

func WithQueryParameters[T any](queryParams T) RequestConfigurationOption

WithQueryParameters sets the query parameters for the request.

func WithResponse

func WithResponse(response Response) RequestConfigurationOption

WithResponse sets the response handler for the request.

type RequestHeader

type RequestHeader interface {
	Set(key, value string)
	Get(key string) string
	SetAll(headers http.Header)
	Iterate(callback func(string, []string) bool)
}

func NewRequestHeader

func NewRequestHeader() RequestHeader

type RequestInformation

type RequestInformation interface {
	SetStreamContent(content []byte)
	GetContent() []byte
	GetMethod() string
	GetHeaders() RequestHeader
	AddQueryParameters(source interface{}) error
	SetUri(url *url.URL)
	Url() (string, error)
	SetContent(content []byte, contentType string)
	ToRequest() (*http.Request, error)
	ToRequestWithContext(ctx context.Context) (*http.Request, error)
	AddHeaders(rawHeaders interface{}) error
}

func NewRequestInformation

func NewRequestInformation(opts ...requestInformationOption) RequestInformation

NewRequestInformation creates a new RequestInformation object with default values.

func NewRequestInformationWithMethod

func NewRequestInformationWithMethod(method HttpMethod) RequestInformation

type RequestOption

type RequestOption interface {
	// GetKey returns the key to store the current option under.
	GetKey() RequestOptionKey
}

Represents a request option.

type RequestOptionKey

type RequestOptionKey struct {
	// The unique key for the option.
	Key string
}

RequestOptionKey represents a key to store a request option under.

type Response

type Response interface {
	ParseHeaders(headers http.Header)
}

Response represents all possible responses

type Test

type Test[T any] struct {
	Title string
	// Setup to make needed modifications for a specific test
	Setup func()
	// Cleanup to undo changes do to reusable items
	Cleanup  func()
	Input    interface{}
	Expected T
	//shouldErr   bool
	ExpectedErr error
}

type UrlInformation

type UrlInformation struct {
	// The Query Parameters of the request.
	QueryParameters map[string]string
	// The path parameters to use for the URL template when generating the URI.
	PathParameters map[string]string
	// The Url template for the current request.
	UrlTemplate string //nolint:stylecheck
}

UrlInformation represents an abstract Url.

func NewURLInformation

func NewURLInformation() *UrlInformation

NewURLInformation creates a new RequestUri object.

func NewUrlInformation deprecated

func NewUrlInformation() *UrlInformation

Deprecated: deprecated as of v1.4.0, use `NewURLInformation` instead.

NewUrlInformation creates a new RequestUri object.

func (*UrlInformation) AddQueryParameters

func (uI *UrlInformation) AddQueryParameters(source interface{}) error

AddQueryParameters adds the query parameters to the request by reading the properties from the provided object.

func (*UrlInformation) ToUrl

func (uI *UrlInformation) ToUrl() (*url.URL, error)

ToUrl retrieves the URI, either from the raw URL or the URL template.

Jump to

Keyboard shortcuts

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