response

package
v0.0.0-...-499b85e Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 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. see https://github.com/owncloud/core/blob/c08baf580927ecb8ec179028dda255fdd85b4568/lib/private/legacy/api.php#L528 also HTTP status codes for apps are the same as OCS codes see https://github.com/owncloud/core/blob/b9ff4c93e051c94adfb301545098ae627e52ef76/lib/public/AppFramework/OCSController.php#L142-L150 I think this is a bug in the ocs v2 api, but since we are going to mimic bugs in ocis ... here goes

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 {
	Meta data.Meta   `json:"meta" xml:"meta"`
	Data interface{} `json:"data,omitempty" xml:"data,omitempty"`
}

Payload combines response metadata and data

type Response

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

Response is the top level response structure

func (Response) MarshalXML

func (rsp Response) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error)

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

func (*Response) Render

func (rsp *Response) Render(w http.ResponseWriter, r *http.Request) error

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

Jump to

Keyboard shortcuts

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