Documentation ¶
Index ¶
- Variables
- func APIVersion(ctx context.Context) string
- func OcsV1StatusCodes(meta Meta) int
- func OcsV2StatusCodes(meta Meta) int
- func VersionCtx(next http.Handler) http.Handler
- func WriteOCSData(w http.ResponseWriter, r *http.Request, m Meta, d interface{}, err error)
- func WriteOCSError(w http.ResponseWriter, r *http.Request, c int, m string, err error)
- func WriteOCSResponse(w http.ResponseWriter, r *http.Request, res Response, err error)
- func WriteOCSSuccess(w http.ResponseWriter, r *http.Request, d interface{})
- type Meta
- type Payload
- type Response
Constants ¶
This section is empty.
Variables ¶
var MetaBadRequest = Meta{Status: "error", StatusCode: 400, Message: "Bad Request"}
MetaBadRequest is used for unknown errors.
var MetaNotFound = Meta{Status: "error", StatusCode: 998, Message: "Not Found"}
MetaNotFound is returned when trying to access not existing resources.
var MetaOK = Meta{Status: "ok", StatusCode: 100, Message: "OK"}
MetaOK is the default ok response.
var MetaServerError = Meta{Status: "error", StatusCode: 996, Message: "Server Error"}
MetaServerError is returned on server errors.
MetaUnauthorized is returned on unauthorized requests.
var MetaUnknownError = Meta{Status: "error", StatusCode: 999, Message: "Unknown Error"}
MetaUnknownError is used for unknown errors.
Functions ¶
func APIVersion ¶
APIVersion retrieves the api version from the context.
func OcsV1StatusCodes ¶
OcsV1StatusCodes returns the http status codes for the OCS API v1.
func OcsV2StatusCodes ¶
OcsV2StatusCodes maps the OCS codes to http status codes for the ocs API v2.
func VersionCtx ¶
WithAPIVersion puts the api version in the context.
func WriteOCSData ¶
WriteOCSData handles writing ocs data in json and xml.
func WriteOCSError ¶
WriteOCSError handles writing error ocs responses.
func WriteOCSResponse ¶
WriteOCSResponse handles writing ocs responses in json and xml.
func WriteOCSSuccess ¶
func WriteOCSSuccess(w http.ResponseWriter, r *http.Request, d interface{})
WriteOCSSuccess handles writing successful ocs response data.
Types ¶
type Meta ¶
type Meta struct { Status string `json:"status" xml:"status"` StatusCode int `json:"statuscode" xml:"statuscode"` Message string `json:"message" xml:"message"` TotalItems string `json:"totalitems,omitempty" xml:"totalitems,omitempty"` ItemsPerPage string `json:"itemsperpage,omitempty" xml:"itemsperpage,omitempty"` }
Meta holds response metadata.
type Payload ¶
type Payload struct { XMLName struct{} `json:"-" xml:"ocs"` Meta Meta `json:"meta" xml:"meta"` Data interface{} `json:"data,omitempty" xml:"data,omitempty"` }
Payload combines response metadata and data.
func (Payload) MarshalXML ¶
MarshalXML handles ocs specific wrapping of array members in 'element' tags for the data.