internal

package
v1.7.0-preview20240421 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeHeader = "Content-Type"
	AcceptHeader      = "Accept"
	BinaryContentType = "application/octet-steam"
	JSONContentType   = "application/json"
	RawURLKey         = "request-raw-url"
)
View Source
const (
	BasePathParameter = "baseurl"
)

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

FromJSON[T] Unmarshalls response body into v

func IsNil added in v1.6.0

func IsNil(a interface{}) bool

IsNil checks if a value is nil or a nil interface

func NewRequestHeader

func NewRequestHeader() core.RequestHeader

func ParseResponse

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

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

Types

type AuthorizationHandler added in v1.6.0

type AuthorizationHandler struct {
	*BaseHandler
	// contains filtered or unexported fields
}

func NewAuthorizationHandler added in v1.6.0

func NewAuthorizationHandler(provider AuthorizationProvider) *AuthorizationHandler

func (*AuthorizationHandler) Handle added in v1.6.0

func (a *AuthorizationHandler) Handle(request RequestInformation) error

type AuthorizationProvider added in v1.6.0

type AuthorizationProvider interface {
	AuthorizeRequest(request RequestInformation) error
}

type BaseAuthorizationProvider added in v1.6.0

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

func NewBaseAuthorizationProvider added in v1.6.0

func NewBaseAuthorizationProvider(credential Credential) (*BaseAuthorizationProvider, error)

func (*BaseAuthorizationProvider) AuthorizeRequest added in v1.6.0

func (b *BaseAuthorizationProvider) AuthorizeRequest(request RequestInformation) error

type BaseHandler added in v1.6.0

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

func NewBaseHandler added in v1.6.0

func NewBaseHandler() *BaseHandler

func (*BaseHandler) Handle added in v1.6.0

func (b *BaseHandler) Handle(request RequestInformation) error

func (*BaseHandler) Next added in v1.6.0

func (b *BaseHandler) Next() RequestHandler

func (*BaseHandler) SetNext added in v1.6.0

func (b *BaseHandler) SetNext(handler RequestHandler)

SetNext method for BaseHandler

type Credential added in v1.6.0

type Credential interface {
	GetAuthentication() (string, error)
}

type ErrorMapping

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

type QueryParameter

type QueryParameter map[string]string

type RequestBody

type RequestBody map[string]interface{}

RequestBody is a type alias for http request bodies

type RequestConfiguration

type RequestConfiguration interface {
	Header() RequestHeader
	Query() map[string]string
	Data() string
	ErrorMapping() ErrorMapping
	SetResponse(interface{})
}

type RequestHandler added in v1.6.0

type RequestHandler interface {
	Handle(RequestInformation) error
	SetNext(RequestHandler)
	Next() RequestHandler
}

type RequestHeader

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

RequestHeader is a type alias for http request headers

func (*RequestHeader) Get

func (rH *RequestHeader) Get(key string) string

func (*RequestHeader) Iterate

func (rH *RequestHeader) Iterate(callback func(string, []string) bool)

func (*RequestHeader) Set

func (rH *RequestHeader) Set(key, value string)

func (*RequestHeader) SetAll

func (rH *RequestHeader) SetAll(headers http.Header)

type RequestInformation added in v1.6.0

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

type Response

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

Response represents all possible responses

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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