client

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoGeneratedRequest

func DoGeneratedRequest[ResponseType any](
	r *http.Request, responseObj *ResponseType,
) error

func DoRequest

func DoRequest[RequestType HttpRequest, ResponseType any](
	baseUrl string,
	clientRequest RequestType,
	responseObj *ResponseType,
) error

func FromSwaggestTag

func FromSwaggestTag(field reflect.StructField) (requestPart, alias, jsonAlias string, ok bool)

func GenerateClientRequest

func GenerateClientRequest(baseUrl string, serviceRequest HttpRequest) (*http.Request, error)

func GetAdditionalLogs

func GetAdditionalLogs(resp interface{}) map[string]interface{}

GetAdditionalLogs

If a response implements response.ExtendedLog, then this function will retrieve the attached logs and return.

func GetCtxHeadersFromContext

func GetCtxHeadersFromContext(ctx context.Context) map[string]interface{}

GetCtxHeadersFromContext

Retrieve the saved headers from the request context. Returns nil if not found.

func GetFriendlyRequestName

func GetFriendlyRequestName(req interface{}) string

GetFriendlyRequestName

Gets the friendly request name of an object. If the object does not implement a known type, this function will use reflection to get the objects type name.

func GetRequestBodyLimit

func GetRequestBodyLimit(ctx context.Context) *int

GetRequestBodyLimit

Gets the request body size limit that was assigned. If this value is not present, the result will be nil.

func InjectCtxHeaders

func InjectCtxHeaders(ctx *context.Context, headers map[string]interface{})

InjectCtxHeaders

Inject the given context with the given headers. No-op if context is nil.

func MixinCtxHeaders

func MixinCtxHeaders(ctx context.Context, headers map[string]interface{}) context.Context

MixinCtxHeaders

Similar in function to InjectCtxHeaders, except this will use the WithValue pattern and return a wrapped context.Context value.

Types

type BasicResponse

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

BasicResponse

When embedded into a Response object, this wil provide basic functionality

func (*BasicResponse) NewCode

func (b *BasicResponse) NewCode(code int)

func (BasicResponse) StatusCode

func (b BasicResponse) StatusCode() int

StatusCode

Returns the status code set by the NewError method

type CodedResponse

type CodedResponse interface {
	NewCode(code int)
}

CodedResponse An object implementing this can track the response code from server / client. Complements kitDefaults.StatusCoder

type Decorator

type Decorator interface {
	UsingDecorator() func(handler http.Handler) http.Handler
}

Decorator

Executes per request, before the request. Use to apply special CORS rules for a single request. The returned function will be passed the http.Handler associated with the request.

type ErredResponse

type ErredResponse interface {
	NewError(code int, format string, vars ...interface{})
}

ErredResponse An object implementing this can track the error from the server / client. Complements error interface

type ErrorResponse

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

ErrorResponse

When embedded into a Response object, this wil provide error handling functionality

func (ErrorResponse) Error

func (b ErrorResponse) Error() string

Error

Implements error interface

func (ErrorResponse) Failed

func (b ErrorResponse) Failed() error

Failed

Implements kitDefaults.Failer

func (*ErrorResponse) NewCode

func (b *ErrorResponse) NewCode(code int)

func (*ErrorResponse) NewError

func (b *ErrorResponse) NewError(code int, format string, vars ...interface{})

NewError

Use this function when it is necessary to indicate an error result for business logic

func (ErrorResponse) StatusCode

func (b ErrorResponse) StatusCode() int

type ExpandedLogging

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

ExpandedLogging

Added to a response, should enable additional request-scoped log values

func (*ExpandedLogging) GetAll

func (l *ExpandedLogging) GetAll() map[string]interface{}

GetAll

creates defensive copy of the underlying map

func (*ExpandedLogging) Log

func (l *ExpandedLogging) Log(values ...interface{})

Log

create a new log entry to be traversed later

type ExtendedLog

type ExtendedLog interface {
	GetAll() map[string]interface{}
}

type HttpRequest

type HttpRequest interface {
	Info() HttpRouteInfo
}

HttpRequest

Indicates essential fields that provide the ability to tag and categorize requests for logging, metrics and other functionality.

type HttpRouteInfo

type HttpRouteInfo struct {
	// Name
	//
	// The name of the request that is sent to the logging middleware. This MUST be unique
	// among all other services that are defined.
	Name string
	// Method
	//
	// HTTP request Method
	Method Method
	// Path
	//  eg. "/path/one" or "v1/path/two"
	// The relative path to the custom root path provided.
	Path string
	// Description
	//
	// A helpful text that describes the service. This will appear in logs.
	Description string
}

type JSONBody

type JSONBody struct{}

JSONBody

When embedded into a request, flags the request as a JSON body to allow for automatic decoding.

type JsonBodyForm

type JsonBodyForm interface {
	// contains filtered or unexported methods
}

type Method

type Method string
const (
	GET     Method = "GET"
	PUT     Method = "PUT"
	DELETE  Method = "DELETE"
	POST    Method = "POST"
	PATCH   Method = "PATCH"
	HEAD    Method = "HEAD"
	OPTIONS Method = "OPTIONS"
)

type OpenAPIExtended

type OpenAPIExtended interface {
	OpenAPIExtensions() map[string]interface{}
}

OpenAPIExtended

Provides the ability to attach openAPI extensions to a request object. These extensions will be parsed by the openapi spec generator and added to the operation.

type OpenAPISecure

type OpenAPISecure interface {
	OpenAPISecurity() []map[string][]string
}

OpenAPISecure

Provides the ability to attach security extensions to a request object. These extensions will be parsed by the openapi spec generator and added to the operation.

type SkipClientValidation

type SkipClientValidation interface {
	SkipClientValidation()
}

type UsingSkipClientValidation added in v1.2.2

type UsingSkipClientValidation struct{}

func (UsingSkipClientValidation) SkipClientValidation added in v1.2.2

func (u UsingSkipClientValidation) SkipClientValidation()

type Validator

type Validator interface {
	// Validate
	//
	// This method, when implemented, will perform one or more validations of the state of the
	// request after being received from the client. If the state is not accepted, a non-nil result
	// is returned for the accompanying error.
	Validate() error
}

Validator

Indicates that the request will have an accompanying validation.

Jump to

Keyboard shortcuts

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