response

package
v0.14.5 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IdTypeString IdType = iota
	IdTypeUuid

	IdPropertyName    = "id"
	SubIdPropertyName = "subId"
)
View Source
const ZitiControllerVersionHeader = "ziti-version"

Variables

This section is empty.

Functions

func AddVersionHeader

func AddVersionHeader(rw http.ResponseWriter)

func RespondWithCreated

func RespondWithCreated(data interface{}, meta *Meta, link *Link, rc *RequestContext)

func RespondWithOk

func RespondWithOk(data interface{}, meta *Meta, rc *RequestContext)

func RespondWithSimpleCreated

func RespondWithSimpleCreated(id string, link *Link, rc *RequestContext)

Types

type ApiResponseBody

type ApiResponseBody struct {
	Meta *Meta       `json:"meta"`
	Data interface{} `json:"data"`
}

func NewApiResponseBody

func NewApiResponseBody(data interface{}, meta *Meta) *ApiResponseBody

type ErrorResponse

type ErrorResponse struct {
	*apierror.ApiError
	Type string
	Args map[string]interface{}
}

func NewErrorResponse

func NewErrorResponse(apiErr *apierror.ApiError, args map[string]interface{}) (*ErrorResponse, error)

func (*ErrorResponse) Respond

func (er *ErrorResponse) Respond(rc *RequestContext) error

type EventLogger

type EventLogger interface {
	Log(actorType, actorId, eventType, entityType, entityId, formatString string, formatData []string, data map[interface{}]interface{})
}

type IdType

type IdType int

type Identifier

type Identifier interface {
	GetId() string
	GetSelfUrl() url.URL
}
type Link struct {
	Href    string `json:"href"`
	Method  string `json:"method,omitempty"`
	Comment string `json:"comment,omitempty"`
}
func NewLink(path string) *Link
type Links map[string]*Link

type Meta

type Meta map[string]interface{}

type RequestContext

type RequestContext struct {
	Id                uuid.UUID
	ApiSession        *model.ApiSession
	Identity          *model.Identity
	ActivePermissions []string
	ResponseWriter    http.ResponseWriter
	Request           *http.Request
	RequestResponder  RequestResponder
	EventLogger       EventLogger
}

func (*RequestContext) GetIdFromRequest

func (rc *RequestContext) GetIdFromRequest(idType IdType) (string, error)

func (*RequestContext) GetSubIdFromRequest

func (rc *RequestContext) GetSubIdFromRequest() (string, error)

type RequestResponder

type RequestResponder interface {
	RespondWithFieldError(err *validation.FieldError)
	RespondWithApiError(apiError *apierror.ApiError)
	RespondWithCouldNotParseBody(e error)
	RespondWithCouldNotReadBody(e error)
	RespondWithCreatedId(id string, link *Link)
	RespondWithCreated(data interface{}, meta *Meta, link *Link)
	RespondWithError(e error)
	RespondWithNotFound()
	RespondWithOk(data interface{}, meta *Meta)
	RespondWithUnauthorizedError(rc *RequestContext)
	RespondWithValidationErrors(ves *schema.ValidationErrors)
	RespondWithMethodNotAllowed()
}

func NewRequestResponder

func NewRequestResponder(rc *RequestContext) RequestResponder

type RequestResponderFactory

type RequestResponderFactory func(rc *RequestContext) RequestResponder

type RequestResponderImpl

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

func (*RequestResponderImpl) RespondWithApiError

func (rr *RequestResponderImpl) RespondWithApiError(apiError *apierror.ApiError)

func (*RequestResponderImpl) RespondWithCouldNotParseBody

func (rr *RequestResponderImpl) RespondWithCouldNotParseBody(e error)

func (*RequestResponderImpl) RespondWithCouldNotReadBody

func (rr *RequestResponderImpl) RespondWithCouldNotReadBody(e error)

func (*RequestResponderImpl) RespondWithCreated

func (rr *RequestResponderImpl) RespondWithCreated(data interface{}, meta *Meta, link *Link)

func (*RequestResponderImpl) RespondWithCreatedId

func (rr *RequestResponderImpl) RespondWithCreatedId(id string, link *Link)

func (*RequestResponderImpl) RespondWithError

func (rr *RequestResponderImpl) RespondWithError(e error)

func (*RequestResponderImpl) RespondWithFieldError

func (rr *RequestResponderImpl) RespondWithFieldError(err *validation.FieldError)

func (*RequestResponderImpl) RespondWithMethodNotAllowed added in v0.9.6

func (rr *RequestResponderImpl) RespondWithMethodNotAllowed()

func (*RequestResponderImpl) RespondWithNotFound

func (rr *RequestResponderImpl) RespondWithNotFound()

func (*RequestResponderImpl) RespondWithOk

func (rr *RequestResponderImpl) RespondWithOk(data interface{}, meta *Meta)

func (*RequestResponderImpl) RespondWithUnauthorizedError

func (rr *RequestResponderImpl) RespondWithUnauthorizedError(*RequestContext)

func (*RequestResponderImpl) RespondWithValidationErrors

func (rr *RequestResponderImpl) RespondWithValidationErrors(e *schema.ValidationErrors)

type Responder

type Responder interface {
	Respond(rc *RequestContext) error
}

type Response

type Response struct {
	Contents       interface{}
	HttpStatusCode int
}

func NewApiEntityResponder

func NewApiEntityResponder(data interface{}, meta *Meta, httpStatusCode int) (*Response, error)

func NewEntityResponse

func NewEntityResponse(contents interface{}, httpStatusCode int) (*Response, error)

func (*Response) Respond

func (r *Response) Respond(w http.ResponseWriter) error

Jump to

Keyboard shortcuts

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