handler

package
v0.0.0-...-460480a Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2018 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Created   int = http.StatusCreated
	OK        int = http.StatusOK
	NoContent int = http.StatusNoContent
)

Http status

Variables

View Source
var (
	ErrActivation     = NewAPIError(activationFail, "Activation failed", "The token might be wrong", http.StatusConflict)
	ErrAliasRequired  = NewAPIError(aliasRequired, "Alias required", "Creation name should be unique in a package : creation %s should have an alias", http.StatusBadRequest)
	ErrBadCreds       = NewAPIError(badCreds, "Wrong credentials", "Unknown email or password invalid", http.StatusUnauthorized)
	ErrBadFileFormat  = NewAPIError(badFileFormat, "Server can't handle this file", "Allowed formats are : %s", http.StatusBadRequest)
	ErrBadForm        = NewAPIError(badForm, "Form invalid", "", http.StatusBadRequest)
	ErrBadScriptDoc   = NewAPIError(badScriptDoc, "Missing document initializer", "Document initializer is required and shloud be in the constructor : %s", http.StatusBadRequest)
	ErrBadScriptClass = NewAPIError(badScriptClass, "Missing class", "Class Woobly is mandatory", http.StatusBadRequest)
	ErrBadScriptConst = NewAPIError(badScriptConst, "Missing constructor", "A constructor is mandatory : %s", http.StatusBadRequest)
	ErrBetterPlan     = NewAPIError(betterPlan, "Already has a better plan", "Current plan %s and requested plan is %s", http.StatusConflict)
	ErrCreaNotAvail   = NewAPIError(creaNotAvail, "Creation not available", "The creation %s is not available", http.StatusConflict)
	ErrCreaVersion    = NewAPIError(creaVersion, "Bad version", "Version %s can't be created", http.StatusBadRequest)
	ErrDB             = NewAPIError(dbFail, "Database error", "Database failed to process the request", http.StatusConflict)
	ErrIntServ        = NewAPIError(servIntErr, "Internal server error", "Something wrong happened", http.StatusInternalServerError)
	ErrPlanLimit      = NewAPIError(planLimit, "Plan limit exceeded", "Number of %s limited by actual plan %s", http.StatusUnauthorized)
	ErrResNotFound    = NewAPIError(resNotFound, "Resource not found", "%s %v not found", http.StatusNotFound)
	ErrServ           = NewAPIError(servErr, "Internal server error", "Something wrong happened while processing %s", http.StatusInternalServerError)
)

API errors

Functions

func DELETECreation

func DELETECreation(c *gin.Context)

DELETECreation delete the creation of the authenticated user

func DELETEPackage

func DELETEPackage(c *gin.Context)

DELETEPackage deletes a package

func DELETEUser

func DELETEUser(c *gin.Context)

DELETEUser delete the authenticated user

func GETCreationCode

func GETCreationCode(c *gin.Context)

GETCreationCode return creation source

func GETCreations

func GETCreations(c *gin.Context)

GETCreations is a handler that returns one or more creations

func GETPackages

func GETPackages(c *gin.Context)

GETPackages is a handler that returns one or more packages

func GETPlans

func GETPlans(c *gin.Context)

GETPlans is handlers that returns all Wooble plans

func GETTags

func GETTags(c *gin.Context)

GETTags is a handler that returns tags

func GETUser

func GETUser(c *gin.Context)

GETUser returns one users with private infos if authenticated, with public infos if not

func GenerateToken

func GenerateToken(c *gin.Context)

GenerateToken generates a new token

func HandleErrors

func HandleErrors(c *gin.Context)

HandleErrors handle API errors

func PATCHCreation

func PATCHCreation(c *gin.Context)

PATCHCreation patches a creation

func PATCHPackage

func PATCHPackage(c *gin.Context)

PATCHPackage patches a packages

func PATCHUser

func PATCHUser(c *gin.Context)

PATCHUser update authenticated user's password

func POSTCreation

func POSTCreation(c *gin.Context)

POSTCreation creates a new creation

func POSTCreationVersion

func POSTCreationVersion(c *gin.Context)

POSTCreationVersion creates a new version

func POSTFile

func POSTFile(c *gin.Context)

POSTFile is a handler to upload a file

func POSTPackage

func POSTPackage(c *gin.Context)

POSTPackage is a handler that create am empty Wooble package

func POSTUser

func POSTUser(c *gin.Context)

POSTUser saves a new user in the database

func POSTUserBank

func POSTUserBank(c *gin.Context)

POSTUserBank creates bank info for customer (only for funds)

func POSTWebhooks

func POSTWebhooks(c *gin.Context)

POSTWebhooks post webhooks (for Stripe)

func PUTCreation

func PUTCreation(c *gin.Context)

PUTCreation edits creation information

func PUTPackage

func PUTPackage(c *gin.Context)

PUTPackage is an handler that updates a package

func PUTPackageCreation

func PUTPackageCreation(c *gin.Context)

PUTPackageCreation updates a package creation

func PushCreation

func PushCreation(c *gin.Context)

PushCreation is an handler that pushes one or more creations in a package

func RefreshToken

func RefreshToken(c *gin.Context)

RefreshToken refreshes a token (lifetime is given in the server conf file $CONFPATH)

func RemovePackageCreation

func RemovePackageCreation(c *gin.Context)

RemovePackageCreation remove a creation from a package

func SaveVersion

func SaveVersion(c *gin.Context)

SaveVersion save the current code for a version (must be in draft state)

Types

type APIError

type APIError struct {
	Code    errCode                `json:"code"`
	Title   string                 `json:"title"`
	Details string                 `json:"details,omitempty"`
	Status  int                    `json:"status"`
	Params  map[string]interface{} `json:"params,omitempty"`
}

APIError is a struct that standardize a Wooble error

func NewAPIError

func NewAPIError(code errCode, title string, details string, status int) APIError

NewAPIError creates an APIError

func (APIError) SetParams

func (e APIError) SetParams(params ...interface{}) APIError

SetParams adds params to APIError, parameters must be in as the following : key(string), value(interface) ...

func (APIError) ValidationError

func (e APIError) ValidationError(ve validator.FieldError) APIError

ValidationError builds and sets validation errors

type APIErrors

type APIErrors struct {
	Errors []APIError `json:"errors,omitempty"`
}

APIErrors wrap all API errors

func (*APIErrors) Error

func (e *APIErrors) Error(err APIError)

Error appends a new API error

func (*APIErrors) HTTPStatus

func (e *APIErrors) HTTPStatus() int

HTTPStatus returns the HTTP status of errors

func (*APIErrors) HasErrors

func (e *APIErrors) HasErrors() bool

HasErrors tells if the is any error

type JSONRes

type JSONRes struct {
	Data interface{} `json:"data,omitempty"`
}

JSONRes is a standardized JSON response

func NewRes

func NewRes(data interface{}) *JSONRes

NewRes initializes a reponse

func (*JSONRes) Response

func (j *JSONRes) Response(data interface{})

Response sets the response

Jump to

Keyboard shortcuts

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