Documentation ¶
Index ¶
- Constants
- Variables
- func AppendAccessControlFuncs(userGroup string, acFuncs ...*gin.HandlerFunc)
- func AuthedCGET(category uint8, relativePath, userGroup string, handler ...*gin.HandlerFunc) error
- func AuthedCPOST(category uint8, relativePath, userGroup string, handler ...*gin.HandlerFunc) error
- func AuthedGET(relativePath, userGroup string, handler ...*gin.HandlerFunc) error
- func AuthedPOST(relativePath, userGroup string, handler ...*gin.HandlerFunc) error
- func CGET(category uint8, relativePath string, handler ...*gin.HandlerFunc) error
- func CPOST(category uint8, relativePath string, handler ...*gin.HandlerFunc) error
- func FinalizeGinEngine(router *gin.Engine, pathPrefix string)
- func GET(relativePath string, handler ...*gin.HandlerFunc) error
- func InheritAccessControlFuncs(userGroup, parentUserGroup string) error
- func MessageResponse(status ResponseStatus, message string) gin.H
- func POST(relativePath string, handler ...*gin.HandlerFunc) error
- func PayloadResponse(status ResponseStatus, payload interface{}) gin.H
- func RegisterAccessControlFuncs(userGroup string, acFuncs ...*gin.HandlerFunc)
- func SampleAccessControlFunc(c *gin.Context)
- type ResponseStatus
Constants ¶
const ( Assets uint8 = iota Auth Billing Internal Payment PaymentCallback Plugin Server )
API categories. Any package (no matter official or third party) except for main package must choose a category to register the API endpoints.
Variables ¶
var ( ErrBadMethod error = errors.New("api: bad method") ErrInvalidCategory error = errors.New("api: invalid category is selected") ErrNotAllowDirectFuncReg error = errors.New("api: no direct handler func registration is allowed") ErrRepeatGetPath error = errors.New("api: repeated path for GET method") ErrRepeatPostPath error = errors.New("api: repeated path for POST method") ErrUnknownUserGroup error = errors.New("api: usergroup has no known access control function") ErrInvalidUserGroup error = errors.New("api: invalid usergroup") ErrAccessControlFuncNotFound error = errors.New("api: access control function not found") )
Functions ¶
func AppendAccessControlFuncs ¶ added in v0.1.0
func AppendAccessControlFuncs(userGroup string, acFuncs ...*gin.HandlerFunc)
AppendAccessControlFunc adds new Access Control Funcs after the existing ones
func AuthedCGET ¶ added in v0.0.9
func AuthedCGET(category uint8, relativePath, userGroup string, handler ...*gin.HandlerFunc) error
func AuthedCPOST ¶ added in v0.0.9
func AuthedCPOST(category uint8, relativePath, userGroup string, handler ...*gin.HandlerFunc) error
func AuthedGET ¶ added in v0.0.9
func AuthedGET(relativePath, userGroup string, handler ...*gin.HandlerFunc) error
func AuthedPOST ¶ added in v0.0.9
func AuthedPOST(relativePath, userGroup string, handler ...*gin.HandlerFunc) error
func CGET ¶ added in v0.0.6
func CGET(category uint8, relativePath string, handler ...*gin.HandlerFunc) error
CGET() stands for Categorized GET CGET(Payment, "dummy/test", f) will register f() as example.com/api/payment/dummy/test for GET method Not validating the authentication header.
func CPOST ¶ added in v0.0.6
func CPOST(category uint8, relativePath string, handler ...*gin.HandlerFunc) error
CPOST() stands for Categorized POST CPOST(Payment, "dummy/test", f) will register f() as example.com/api/payment/dummy/test for POST method Not validating the authentication header.
func FinalizeGinEngine ¶ added in v0.0.3
FinalizeGinEngine() binds all registered handlers to a gin.Engine. - pathPrefix should be in the format of aaa[/bbb[/ccc[/ddd]]] where [] encloses an optional portion
func GET ¶ added in v0.0.6
func GET(relativePath string, handler ...*gin.HandlerFunc) error
GET() is effectively like gin.Engine.GET() security measure: only main package can call GET(). For modules, refer to CGET() Warning: this function by-default registers routes which have no AUTHORIZATION. Use AuthedGET() instead!
func InheritAccessControlFuncs ¶ added in v0.1.0
InheritAccessControlFunc inherits Access Control Funcs from parent user group if the userGroup exists, it appends parent's Access Control Funcs after the existing ones
func MessageResponse ¶ added in v0.0.9
func MessageResponse(status ResponseStatus, message string) gin.H
MessageResponse() creates a simple response with only status and message properties and registers the message to a map. Frontend may request the map at anytime for application localization/user-friendlization purposes. Recommended for: Create/Update/Delete actions
func POST ¶ added in v0.0.6
func POST(relativePath string, handler ...*gin.HandlerFunc) error
POST() is effectively like gin.Engine.POST(), but takes 1 handler function only security measure: only main package can call POST(). For modules, refer to CPOST() Warning: this function by-default registers routes which have no AUTHORIZATION. Use AuthedPOST() instead!
func PayloadResponse ¶ added in v0.0.9
func PayloadResponse(status ResponseStatus, payload interface{}) gin.H
PayloadResponse() creates a response with status and payload properties. Where payload could be a random typed interface. Recommended for: Read actions
func RegisterAccessControlFuncs ¶ added in v0.1.0
func RegisterAccessControlFuncs(userGroup string, acFuncs ...*gin.HandlerFunc)
RegisterAccessControlFunc wipes all existing Access Control Funcs and replace it with the new ones
func SampleAccessControlFunc ¶ added in v0.0.9
Types ¶
type ResponseStatus ¶ added in v0.0.9
type ResponseStatus uint8
const ( CANCELED ResponseStatus = iota ERROR SUCCESS )