api

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

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 GetFields

func GetFields(body []byte) (fields.UpdatedFields, error)

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.

func WrapCorsHandler

func WrapCorsHandler(innerHandler http.Handler) http.Handler

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

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) bool
	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) bool

func (*ResponderImpl) RespondWithValidationErrors

func (responder *ResponderImpl) RespondWithValidationErrors(errors *apierror.ValidationErrors)

func (*ResponderImpl) SetProducer

func (responder *ResponderImpl) SetProducer(producer runtime.Producer)

type ResponseMapper

type ResponseMapper interface {
	EmptyOkData() interface{}
	MapApiError(requestId string, err *errorz.ApiError) interface{}
}

Jump to

Keyboard shortcuts

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