Documentation
¶
Index ¶
- func DoGeneratedRequest[ResponseType any](r *http.Request, responseObj *ResponseType) error
- func DoRequest[RequestType HttpRequest, ResponseType any](baseUrl string, clientRequest RequestType, responseObj *ResponseType) error
- func FromSwaggestTag(field reflect.StructField) (requestPart, alias, jsonAlias string, ok bool)
- func GenerateClientRequest(baseUrl string, serviceRequest HttpRequest) (*http.Request, error)
- func GetAdditionalLogs(resp interface{}) map[string]interface{}
- func GetCtxHeadersFromContext(ctx context.Context) map[string]interface{}
- func GetFriendlyRequestName(req interface{}) string
- func GetRequestBodyLimit(ctx context.Context) *int
- func InjectCtxHeaders(ctx *context.Context, headers map[string]interface{})
- func MixinCtxHeaders(ctx context.Context, headers map[string]interface{}) context.Context
- type BasicResponse
- type CodedResponse
- type Decorator
- type ErredResponse
- type ErrorResponse
- type ExpandedLogging
- type ExtendedLog
- type HttpRequest
- type HttpRouteInfo
- type JSONBody
- type JsonBodyForm
- type Method
- type OpenAPIExtended
- type OpenAPISecure
- type SkipClientValidation
- type UsingSkipClientValidation
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoGeneratedRequest ¶
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 ¶
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 ¶
GetRequestBodyLimit
Gets the request body size limit that was assigned. If this value is not present, the result will be nil.
func InjectCtxHeaders ¶
InjectCtxHeaders
Inject the given context with the given headers. No-op if context is nil.
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 ¶
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 ¶
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) 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 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 ¶
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.