Documentation
¶
Index ¶
- Constants
- func AddRequestContextToHttpContext(r *http.Request, rc RequestContext)
- func GetFields(body []byte) (fields.UpdatedFields, error)
- func GetJsonFields(prefix string, m map[string]interface{}, result fields.UpdatedFieldsMap)
- func TimeoutHandler(next http.Handler, timeout time.Duration, apiErr *errorz.ApiError, ...) http.Handler
- func WrapCorsHandler(innerHandler http.Handler) http.Handler
- type ContextKey
- type RequestContext
- type RequestContextImpl
- func (rc *RequestContextImpl) GetBody() []byte
- func (rc *RequestContextImpl) GetEntityId() (string, error)
- func (rc *RequestContextImpl) GetEntitySubId() (string, error)
- func (rc *RequestContextImpl) GetId() string
- func (rc *RequestContextImpl) GetRequest() *http.Request
- func (rc *RequestContextImpl) GetResponseWriter() http.ResponseWriter
- func (rc *RequestContextImpl) NewChangeContext() *change.Context
- func (rc *RequestContextImpl) SetEntityId(id string)
- func (rc *RequestContextImpl) SetEntitySubId(id string)
- type Responder
- type ResponderImpl
- func (responder *ResponderImpl) GetProducer() runtime.Producer
- func (responder *ResponderImpl) Respond(data interface{}, httpStatus int)
- func (responder *ResponderImpl) RespondWithApiError(apiError *errorz.ApiError)
- func (responder *ResponderImpl) RespondWithCouldNotParseBody(err error)
- func (responder *ResponderImpl) RespondWithCouldNotReadBody(err error)
- func (responder *ResponderImpl) RespondWithEmptyOk()
- func (responder *ResponderImpl) RespondWithError(err error)
- func (responder *ResponderImpl) RespondWithFieldError(fe *errorz.FieldError)
- func (responder *ResponderImpl) RespondWithNotFound()
- func (responder *ResponderImpl) RespondWithNotFoundWithCause(cause error)
- func (responder *ResponderImpl) RespondWithProducer(producer runtime.Producer, data interface{}, httpStatus int)
- func (responder *ResponderImpl) RespondWithValidationErrors(errors *apierror.ValidationErrors)
- func (responder *ResponderImpl) SetProducer(producer runtime.Producer)
- type ResponseMapper
Constants ¶
View Source
const ( IdPropertyName = "id" SubIdPropertyName = "subId" )
View Source
const ZitiContextKey = ContextKey("context")
View Source
const (
// ZitiSession is the header value used to pass Ziti sessions around
ZitiSession = "zt-session"
)
Variables ¶
This section is empty.
Functions ¶
func AddRequestContextToHttpContext ¶
func AddRequestContextToHttpContext(r *http.Request, rc RequestContext)
func GetJsonFields ¶
func GetJsonFields(prefix string, m map[string]interface{}, result fields.UpdatedFieldsMap)
func TimeoutHandler ¶
func TimeoutHandler(next http.Handler, timeout time.Duration, apiErr *errorz.ApiError, mapper ResponseMapper) http.Handler
TimeoutHandler will create a http.Handler that wraps the given http.Handler. If the given timeout is reached, the supplied errorz.ApiError and ResponseMapper will be used to create an error response. This handler assumes JSON output.
This handler functions by creating a proxy ResponseWriter that is passed to downstream http.Handlers. This proxy ResponseWriter is ignored on timeout and panics. On panic, a blank response is returned with a 500 Internal Error status code. Downstream handlers are encouraged to implement their own panic recovery.
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey is used a custom type to avoid accidental context key collisions
type RequestContext ¶
type RequestContext interface { Responder GetId() string GetBody() []byte GetRequest() *http.Request GetResponseWriter() http.ResponseWriter SetEntityId(id string) SetEntitySubId(id string) GetEntityId() (string, error) GetEntitySubId() (string, error) NewChangeContext() *change.Context }
func GetRequestContextFromHttpContext ¶
func GetRequestContextFromHttpContext(r *http.Request) (RequestContext, error)
type RequestContextImpl ¶
type RequestContextImpl struct { Responder Id string ResponseWriter http.ResponseWriter Request *http.Request Body []byte // contains filtered or unexported fields }
func (*RequestContextImpl) GetBody ¶
func (rc *RequestContextImpl) GetBody() []byte
func (*RequestContextImpl) GetEntityId ¶
func (rc *RequestContextImpl) GetEntityId() (string, error)
func (*RequestContextImpl) GetEntitySubId ¶
func (rc *RequestContextImpl) GetEntitySubId() (string, error)
func (*RequestContextImpl) GetId ¶
func (rc *RequestContextImpl) GetId() string
func (*RequestContextImpl) GetRequest ¶
func (rc *RequestContextImpl) GetRequest() *http.Request
func (*RequestContextImpl) GetResponseWriter ¶
func (rc *RequestContextImpl) GetResponseWriter() http.ResponseWriter
func (*RequestContextImpl) NewChangeContext ¶ added in v0.23.0
func (rc *RequestContextImpl) NewChangeContext() *change.Context
func (*RequestContextImpl) SetEntityId ¶
func (rc *RequestContextImpl) SetEntityId(id string)
func (*RequestContextImpl) SetEntitySubId ¶
func (rc *RequestContextImpl) SetEntitySubId(id string)
type Responder ¶
type Responder interface { Respond(data interface{}, httpStatus int) RespondWithProducer(producer runtime.Producer, data interface{}, httpStatus int) RespondWithEmptyOk() RespondWithError(err error) RespondWithApiError(err *errorz.ApiError) SetProducer(producer runtime.Producer) GetProducer() runtime.Producer RespondWithCouldNotReadBody(err error) RespondWithCouldNotParseBody(err error) RespondWithValidationErrors(errors *apierror.ValidationErrors) RespondWithNotFound() RespondWithNotFoundWithCause(cause error) RespondWithFieldError(fe *errorz.FieldError) }
type ResponderImpl ¶
type ResponderImpl struct {
// contains filtered or unexported fields
}
func NewResponder ¶
func NewResponder(rc RequestContext, mapper ResponseMapper) *ResponderImpl
func (*ResponderImpl) GetProducer ¶
func (responder *ResponderImpl) GetProducer() runtime.Producer
func (*ResponderImpl) Respond ¶
func (responder *ResponderImpl) Respond(data interface{}, httpStatus int)
func (*ResponderImpl) RespondWithApiError ¶
func (responder *ResponderImpl) RespondWithApiError(apiError *errorz.ApiError)
func (*ResponderImpl) RespondWithCouldNotParseBody ¶
func (responder *ResponderImpl) RespondWithCouldNotParseBody(err error)
func (*ResponderImpl) RespondWithCouldNotReadBody ¶
func (responder *ResponderImpl) RespondWithCouldNotReadBody(err error)
func (*ResponderImpl) RespondWithEmptyOk ¶
func (responder *ResponderImpl) RespondWithEmptyOk()
func (*ResponderImpl) RespondWithError ¶
func (responder *ResponderImpl) RespondWithError(err error)
func (*ResponderImpl) RespondWithFieldError ¶
func (responder *ResponderImpl) RespondWithFieldError(fe *errorz.FieldError)
func (*ResponderImpl) RespondWithNotFound ¶
func (responder *ResponderImpl) RespondWithNotFound()
func (*ResponderImpl) RespondWithNotFoundWithCause ¶
func (responder *ResponderImpl) RespondWithNotFoundWithCause(cause error)
func (*ResponderImpl) RespondWithProducer ¶
func (responder *ResponderImpl) RespondWithProducer(producer runtime.Producer, data interface{}, httpStatus int)
func (*ResponderImpl) RespondWithValidationErrors ¶
func (responder *ResponderImpl) RespondWithValidationErrors(errors *apierror.ValidationErrors)
func (*ResponderImpl) SetProducer ¶
func (responder *ResponderImpl) SetProducer(producer runtime.Producer)
type ResponseMapper ¶
Click to show internal directories.
Click to hide internal directories.