controllers

package
v0.0.0-...-09e84be Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(c interface{}, v *web.APIVersion)

Register called from main to register controller

Types

type APIController

type APIController struct {
	Name string
	*web.APIVersion
}

APIController is base for all controllers

func NewAPIController

func NewAPIController(c interface{}, name string, v *web.APIVersion) *APIController

NewAPIController create new instance of BaseController

func (*APIController) BindJSON

func (b *APIController) BindJSON(r *http.Request, obj interface{}) error

BindJSON binds request body to JSON

func (*APIController) Content

func (b *APIController) Content(w http.ResponseWriter, content string)

Content writes given string to response

func (*APIController) Error

func (b *APIController) Error(w http.ResponseWriter, err string, code int, callerName string)

Error set error into response that is later served as JSON

func (*APIController) Error500

func (b *APIController) Error500(w http.ResponseWriter, err string, callerName string)

Error500 return 500-internal server error

func (*APIController) GetClientInfo

func (b *APIController) GetClientInfo(r *http.Request, callerName string) jwtauth.ClientInfo

GetClientInfo retrieve clientinfo from context of authentiated requests only

func (*APIController) JSON

func (b *APIController) JSON(w http.ResponseWriter, data interface{})

JSON set resultant data into response that is injected into Data property of APiResult as JSONString

func (*APIController) JSONRaw

func (b *APIController) JSONRaw(w http.ResponseWriter, data interface{})

JSONRaw set resultant data as JSON of passed data itself. Data not encapsulated in APiResult. Use with caution as called must know what data it will return for parsing.

func (*APIController) JSONReplacer

func (b *APIController) JSONReplacer(w http.ResponseWriter, data interface{}, r *strings.Replacer)

JSONReplacer set resultant data into response APIResult, but before sending response, it makes replacements in JSONString of data as per supplied replacers

func (*APIController) JSONStr

func (b *APIController) JSONStr(w http.ResponseWriter, jsondata string)

JSONStr set resultant data into response that is injected into Data property of APiResult as-it-is without any conversion

type Controller

type Controller interface {
	New(*web.APIVersion)
	//Path(string) string
	SetRoutes() http.Handler
}

Controller provide interface for all controllers

type User

type User struct {
	*APIController
}

User is type for UserController

func (*User) Createuser

func (t *User) Createuser(w http.ResponseWriter, r *http.Request)

Createuser will create new user in database

func (*User) Deleteuser

func (t *User) Deleteuser(w http.ResponseWriter, r *http.Request)

Deleteuser will delete given user by id

func (*User) Listusers

func (t *User) Listusers(w http.ResponseWriter, r *http.Request)

Listusers will list all users

func (*User) New

func (t *User) New(v *web.APIVersion)

New creates New UserController and initialize it with BaseController

func (*User) SetRoutes

func (t *User) SetRoutes() http.Handler

SetRoutes create routes for controller

Jump to

Keyboard shortcuts

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