response

package
v2.24.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MessageGroupNotFound = "The requested group could not be found"

MessageGroupNotFound is used when a group can not be found

View Source
var MessageLockedForSharing = "The file is locked until the file is in use by at least one user"

MessageLockedForSharing is used when a user tries to create a new share until the file is in use by at least one user

View Source
var MessagePathNotFound = "Wrong path, file/folder doesn't exist"

MessagePathNotFound is used when a file or folder can not be found

View Source
var MessageShareExists = "A share for the recipient already exists"

MessageShareExists is used when a user tries to create a new share for the same user

View Source
var MessageUserNotFound = "The requested user could not be found"

MessageUserNotFound is used when a user can not be found

View Source
var MetaBadRequest = Meta{Status: "error", StatusCode: 400, Message: "Bad Request"}

MetaBadRequest is used for unknown errors

View Source
var MetaFailure = Meta{Status: "", StatusCode: 101, Message: "Failure"}

MetaFailure is a failure response with code 101

View Source
var MetaForbidden = Meta{Status: "", StatusCode: 104, Message: "Forbidden"}

MetaForbidden is an error response with code 104

View Source
var MetaInvalidInput = Meta{Status: "", StatusCode: 102, Message: "Invalid Input"}

MetaInvalidInput is an error response with code 102

View Source
var MetaLocked = Meta{Status: "failure", StatusCode: 423, Message: "The file is locked"}

MetaLocked is returned when trying to share not existing resources

View Source
var MetaNotFound = Meta{Status: "error", StatusCode: 998, Message: "Not Found"}

MetaNotFound is returned when trying to access not existing resources

View Source
var MetaOK = Meta{Status: "ok", StatusCode: 100, Message: "OK"}

MetaOK is the default ok response

View Source
var MetaPathNotFound = Meta{Status: "failure", StatusCode: 404, Message: MessagePathNotFound}

MetaPathNotFound is returned when trying to share not existing resources

View Source
var MetaServerError = Meta{Status: "error", StatusCode: 996, Message: "Server Error"}

MetaServerError is returned on server errors

View Source
var MetaUnauthorized = Meta{Status: "error", StatusCode: 997, Message: "Unauthorised"}

MetaUnauthorized is returned on unauthorized requests

View Source
var MetaUnknownError = Meta{Status: "error", StatusCode: 999, Message: "Unknown Error"}

MetaUnknownError is used for unknown errors

Functions

func APIVersion

func APIVersion(ctx context.Context) string

APIVersion retrieves the api version from the context.

func OcsV1StatusCodes

func OcsV1StatusCodes(meta Meta) int

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

func OcsV2StatusCodes

func OcsV2StatusCodes(meta 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

WithAPIVersion puts the api version in the context.

func WriteOCSData

func WriteOCSData(w http.ResponseWriter, r *http.Request, m Meta, d interface{}, err error)

WriteOCSData handles writing ocs data in json and xml

func WriteOCSError

func WriteOCSError(w http.ResponseWriter, r *http.Request, c int, m string, err error)

WriteOCSError handles writing error ocs responses

func WriteOCSResponse

func WriteOCSResponse(w http.ResponseWriter, r *http.Request, res Response, err error)

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

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

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