response

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIVersion

func APIVersion(ctx context.Context) string

APIVersion retrieves the api version from the context.

func DataRender

func DataRender(d interface{}) render.Renderer

DataRender creates an OK Payload for the given data

func ErrRender

func ErrRender(c int, m string) render.Renderer

ErrRender creates an Error Paylod with the given OCS error code and message The httpcode will be determined using the API version stored in the context

func OcsV1StatusCodes

func OcsV1StatusCodes(meta data.Meta) int

OcsV1StatusCodes returns the http status codes for the OCS API v1.

func OcsV2StatusCodes

func OcsV2StatusCodes(meta data.Meta) int

OcsV2StatusCodes maps the OCS codes to http status codes for the ocs API v2.

func VersionCtx

func VersionCtx(next http.Handler) http.Handler

VersionCtx middleware is used to determine the response mapper from the URL parameters passed through as the request. In case the Version is unknown, we stop here and return a 404.

Types

type Payload

type Payload struct {
	XMLName struct{}    `json:"-" xml:"ocs"`
	Meta    data.Meta   `json:"meta" xml:"meta"`
	Data    interface{} `json:"data,omitempty" xml:"data,omitempty"`
}

Payload combines response metadata and data

func (Payload) MarshalXML

func (p Payload) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error)

MarshalXML handles ocs specific wrapping of array members in 'element' tags for the data

func (*Payload) Render

func (p *Payload) Render(w http.ResponseWriter, r *http.Request) error

Render sets the status code of the http response, taking the ocs version into account

type Response

type Response struct {
	OCS *Payload `json:"ocs"`
}

Response is the top level response structure

Jump to

Keyboard shortcuts

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