Documentation ¶
Index ¶
- Constants
- Variables
- func AddAPPStartHook(hf hookfunc)
- func Alert(v ...interface{})
- func Config(returnType, key string, defaultVal interface{}) (value interface{}, err error)
- func Critical(v ...interface{})
- func Debug(v ...interface{})
- func Emergency(v ...interface{})
- func Error(v ...interface{})
- func ExceptMethodAppend(action string)
- func Info(v ...interface{})deprecated
- func Informational(v ...interface{})
- func Notice(v ...interface{})
- func ParseConfig() (err error)
- func Run(params ...string)
- func SetLevel(l int)
- func SetLogFuncCall(b bool)
- func SetLogger(adaptername string, config string) error
- func TestGoCrabInit(apppath string)
- func Trace(v ...interface{})
- func Warn(v ...interface{})deprecated
- func Warning(v ...interface{})
- type App
- func Any(rootpath string, f FilterFunc) *App
- func AutoPrefix(prefix string, c ControllerInterface) *App
- func AutoRouter(c ControllerInterface) *App
- func Delete(rootpath string, f FilterFunc) *App
- func ErrorController(c ControllerInterface) *App
- func Errorhandler(code string, h http.HandlerFunc) *App
- func Get(rootpath string, f FilterFunc) *App
- func Handler(rootpath string, h http.Handler, options ...interface{}) *App
- func Head(rootpath string, f FilterFunc) *App
- func Include(cList ...ControllerInterface) *App
- func InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) *App
- func NewApp() *App
- func Options(rootpath string, f FilterFunc) *App
- func Patch(rootpath string, f FilterFunc) *App
- func Post(rootpath string, f FilterFunc) *App
- func Put(rootpath string, f FilterFunc) *App
- func RESTRouter(rootpath string, c ControllerInterface) *App
- func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *App
- type Controller
- func (c *Controller) Abort(code string)
- func (c *Controller) CustomAbort(status int, body string)
- func (c *Controller) Delete()
- func (c *Controller) Finish()
- func (c *Controller) Get()
- func (c *Controller) GetBool(key string, def ...bool) (bool, error)
- func (c *Controller) GetControllerAndAction() (controllerName, actionName string)
- func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (c *Controller) GetFloat(key string, def ...float64) (float64, error)
- func (c *Controller) GetInt(key string, def ...int) (int, error)
- func (c *Controller) GetInt16(key string, def ...int16) (int16, error)
- func (c *Controller) GetInt32(key string, def ...int32) (int32, error)
- func (c *Controller) GetInt64(key string, def ...int64) (int64, error)
- func (c *Controller) GetInt8(key string, def ...int8) (int8, error)
- func (c *Controller) GetSecureCookie(Secret, key string) (string, bool)
- func (c *Controller) GetString(key string, def ...string) string
- func (c *Controller) GetStrings(key string, def ...[]string) []string
- func (c *Controller) HandlerFunc(fnname string) bool
- func (c *Controller) Head()
- func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{})
- func (c *Controller) Input() url.Values
- func (c *Controller) IsAjax() bool
- func (c *Controller) Mapping(method string, fn func())
- func (c *Controller) Options()
- func (c *Controller) Patch()
- func (c *Controller) Post()
- func (c *Controller) Prepare()
- func (c *Controller) Put()
- func (c *Controller) RESTFaild(data interface{}, message interface{})
- func (c *Controller) RESTHeadCode(code int)
- func (c *Controller) RESTHeadNoContent()
- func (c *Controller) RESTHeadNotFound()
- func (c *Controller) RESTHeadSuccess()
- func (c *Controller) RESTJson(code int, message string, data interface{})
- func (c *Controller) RESTSuccess(data interface{}, message interface{})
- func (c *Controller) Redirect(url string, code int)
- func (c *Controller) Render() error
- func (c *Controller) RenderBytes() ([]byte, error)
- func (c *Controller) RenderString() (string, error)
- func (c *Controller) SaveToFile(fromfile, tofile string) error
- func (c *Controller) ServeFormatted()
- func (c *Controller) ServeJson(encoding ...bool)
- func (c *Controller) ServeJsonp()
- func (c *Controller) ServeString(data []byte)
- func (c *Controller) ServeXml()
- func (c *Controller) SetSecureCookie(Secret, name, value string, others ...interface{})
- func (c *Controller) StopRun()
- func (c *Controller) URLMapping()
- func (c *Controller) UrlFor(endpoint string, values ...interface{}) string
- type ControllerComments
- type ControllerInterface
- type ControllerRegistor
- func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingMethods ...string)
- func (p *ControllerRegistor) AddAuto(c ControllerInterface)
- func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface)
- func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc)
- func (p *ControllerRegistor) Any(pattern string, f FilterFunc)
- func (p *ControllerRegistor) Delete(pattern string, f FilterFunc)
- func (p *ControllerRegistor) Get(pattern string, f FilterFunc)
- func (p *ControllerRegistor) Handler(pattern string, h http.Handler, options ...interface{})
- func (p *ControllerRegistor) Head(pattern string, f FilterFunc)
- func (p *ControllerRegistor) Include(cList ...ControllerInterface)
- func (p *ControllerRegistor) InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) error
- func (p *ControllerRegistor) Options(pattern string, f FilterFunc)
- func (p *ControllerRegistor) Patch(pattern string, f FilterFunc)
- func (p *ControllerRegistor) Post(pattern string, f FilterFunc)
- func (p *ControllerRegistor) Put(pattern string, f FilterFunc)
- func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
- func (p *ControllerRegistor) UrlFor(endpoint string, values ...interface{}) string
- type FilterFunc
- type FilterHandler
- type FilterRouter
- type GoCrabAppConfig
- func (b *GoCrabAppConfig) Bool(key string) (bool, error)
- func (b *GoCrabAppConfig) DIY(key string) (interface{}, error)
- func (b *GoCrabAppConfig) DefaultBool(key string, defaultval bool) bool
- func (b *GoCrabAppConfig) DefaultFloat(key string, defaultval float64) float64
- func (b *GoCrabAppConfig) DefaultInt(key string, defaultval int) int
- func (b *GoCrabAppConfig) DefaultInt64(key string, defaultval int64) int64
- func (b *GoCrabAppConfig) DefaultString(key string, defaultval string) string
- func (b *GoCrabAppConfig) DefaultStrings(key string, defaultval []string) []string
- func (b *GoCrabAppConfig) Float(key string) (float64, error)
- func (b *GoCrabAppConfig) GetSection(section string) (map[string]string, error)
- func (b *GoCrabAppConfig) Int(key string) (int, error)
- func (b *GoCrabAppConfig) Int64(key string) (int64, error)
- func (b *GoCrabAppConfig) SaveConfigFile(filename string) error
- func (b *GoCrabAppConfig) Set(key, val string) error
- func (b *GoCrabAppConfig) String(key string) string
- func (b *GoCrabAppConfig) Strings(key string) []string
- type Tree
Constants ¶
const ( LevelEmergency = iota LevelAlert LevelCritical LevelError LevelWarning LevelNotice LevelInformational LevelDebug )
Log levels to control the logging output.
const ( // default filter execution points BeforeStatic = iota BeforeRouter BeforeExec AfterExec FinishRouter )
const COMMENTFL = "commentsRouter_"
const REST_FAILD_CODE = 999
const REST_FAILD_MSG = "faild"
const REST_SUCCESS_CODE = 1000
const REST_SUCCESS_MSG = "ok"
const RUNMODE_DEV = Core.RUNMODE_DEV
const RUNMODE_PROD = Core.RUNMODE_PROD
const VERSION = Core.VERSION
Variables ¶
var ( CrabApp *App // GoCrab application AppName string AppPath string AppConfigPath string EnableHttpListen bool HttpAddr string HttpPort int ListenTCP4 bool EnableHttpTLS bool HttpsPort int HttpCertFile string HttpKeyFile string RecoverPanic bool // flag of auto recover panic AutoRender bool // flag of render template automatically AppConfig *GoCrabAppConfig RunMode string // run mode, "dev" or "prod" UseFcgi bool UseStdIo bool MaxMemory int64 EnableGzip bool // flag of enable gzip DirectoryIndex bool // flag of display directory index. default is false. HttpServerTimeOut int64 ErrorsShow bool // flag of show errors in page. if true, show error and trace info in page rendered with error template. CopyRequestBody bool // flag of copy raw request body in context. GoCrabServerName string // GoCrab server name exported in response header. AppConfigProvider string // config provider RouterCaseSensitive bool // router case sensitive default is true AccessLogs bool // print access logs, default is false StaticDir map[string]string ViewsPath string ResourcePath string )
var ( // custom error when user stop request handler manually. USERSTOPRUN = errors.New("User stop run") GlobalControllerRouter map[string][]ControllerComments = make(map[string][]ControllerComments) //pkgpath+controller:comments )
var ErrorMaps map[string]*errorInfo
map of http handlers for each error string.
var Logger *logs.Logger
logger references the used application logger.
Functions ¶
func AddAPPStartHook ¶
func AddAPPStartHook(hf hookfunc)
The hookfunc will run in GoCrab.Run() such as middlerware start, buildtemplate, admin start
func ExceptMethodAppend ¶
func ExceptMethodAppend(action string)
To append a slice's value into "exceptMethod", for controller's methods shouldn't reflect to AutoRouter
func Info
deprecated
func Info(v ...interface{})
Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0.
func ParseConfig ¶
func ParseConfig() (err error)
ParseConfig parsed default config file. now only support ini, next will support json.
func Run ¶
func Run(params ...string)
Run GoCrab application. GoCrab.Run() default run on HttpPort GoCrab.Run(":8089") GoCrab.Run("127.0.0.1:8089")
func SetLevel ¶
func SetLevel(l int)
SetLogLevel sets the global log level used by the simple logger.
func SetLogFuncCall ¶
func SetLogFuncCall(b bool)
func Trace ¶
func Trace(v ...interface{})
Trace logs a message at trace level. Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0.
func Warn
deprecated
func Warn(v ...interface{})
Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0.
Types ¶
type App ¶
type App struct { Handlers *ControllerRegistor Server *http.Server }
App defines GoCrab application with a new PatternServeMux.
func Any ¶
func Any(rootpath string, f FilterFunc) *App
register router for all method usage:
GoCrab.Any("/api", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func AutoPrefix ¶
func AutoPrefix(prefix string, c ControllerInterface) *App
AutoPrefix adds controller handler to CrabApp with prefix. it's same to App.AutoRouterWithPrefix. if GoCrab.AutoPrefix("/admin",&MainContorlller{}) and MainController has methods List and Page, visit the url /admin/main/list to exec List function or /admin/main/page to exec Page function.
func AutoRouter ¶
func AutoRouter(c ControllerInterface) *App
AutoRouter adds defined controller handler to CrabApp. it's same to App.AutoRouter. if GoCrab.AddAuto(&MainContorlller{}) and MainController has methods List and Page, visit the url /main/list to exec List function or /main/page to exec Page function.
func Delete ¶
func Delete(rootpath string, f FilterFunc) *App
register router for Delete method usage:
GoCrab.Delete("/api", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func ErrorController ¶
func ErrorController(c ControllerInterface) *App
ErrorController registers ControllerInterface to each http err code string. usage:
GoCrab.ErrorHandler(&controllers.ErrorController{})
func Errorhandler ¶
func Errorhandler(code string, h http.HandlerFunc) *App
ErrorHandler registers http.HandlerFunc to each http err code string. usage:
GoCrab.ErrorHandler("404",NotFound) GoCrab.ErrorHandler("500",InternalServerError)
func Get ¶
func Get(rootpath string, f FilterFunc) *App
register router for Get method usage:
GoCrab.Get("/", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func Handler ¶
register router for own Handler usage:
GoCrab.Handler("/api", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func Head ¶
func Head(rootpath string, f FilterFunc) *App
register router for Head method usage:
GoCrab.Head("/api", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func Include ¶
func Include(cList ...ControllerInterface) *App
Router add list from usage: GoCrab.Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})
type BankAccount struct{ GoCrab.Controller }
register the function
func (b *BankAccount)Mapping(){ b.Mapping("ShowAccount" , b.ShowAccount) b.Mapping("ModifyAccount", b.ModifyAccount) }
//@router /account/:id [get]
func (b *BankAccount) ShowAccount(){ //logic }
//@router /account/:id [post]
func (b *BankAccount) ModifyAccount(){ //logic }
the comments @router url methodlist url support all the function Router's pattern methodlist [get post head put delete options *]
func InsertFilter ¶
func InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) *App
InsertFilter adds a FilterFunc with pattern condition and action constant. The pos means action constant including GoCrab.BeforeStatic, GoCrab.BeforeRouter, GoCrab.BeforeExec, GoCrab.AfterExec and GoCrab.FinishRouter. The bool params is for setting the returnOnOutput value (false allows multiple filters to execute)
func Options ¶
func Options(rootpath string, f FilterFunc) *App
register router for Options method usage:
GoCrab.Options("/api", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func Patch ¶
func Patch(rootpath string, f FilterFunc) *App
register router for Patch method usage:
GoCrab.Patch("/api", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func Post ¶
func Post(rootpath string, f FilterFunc) *App
register router for Post method usage:
GoCrab.Post("/api", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func Put ¶
func Put(rootpath string, f FilterFunc) *App
register router for Put method usage:
GoCrab.Put("/api", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func RESTRouter ¶
func RESTRouter(rootpath string, c ControllerInterface) *App
RESTRouter adds a restful controller handler to CrabApp. its' controller implements GoCrab.ControllerInterface and defines a param "pattern/:objectId" to visit each resource.
func Router ¶
func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *App
Router adds a patterned controller handler to CrabApp. it's an alias method of App.Router. usage:
simple router GoCrab.Router("/admin", &admin.UserController{}) GoCrab.Router("/admin/index", &admin.ArticleController{}) regex router GoCrab.Router("/api/:id([0-9]+)", &controllers.RController{}) custom rules GoCrab.Router("/api/list",&RestController{},"*:ListFood") GoCrab.Router("/api/create",&RestController{},"post:CreateFood") GoCrab.Router("/api/update",&RestController{},"put:UpdateFood") GoCrab.Router("/api/delete",&RestController{},"delete:DeleteFood")
type Controller ¶
type Controller struct { Ctx *context.Context Data map[interface{}]interface{} TplNames string Layout string LayoutSections map[string]string // the key is the section name and the value is the template name TplExt string AppController interface{} EnableRender bool // contains filtered or unexported fields }
Controller defines some basic http request handler operations, such as http context, template and view, session.
func (*Controller) Abort ¶
func (c *Controller) Abort(code string)
Aborts stops controller handler and show the error data if code is defined in ErrorMap or code string.
func (*Controller) CustomAbort ¶
func (c *Controller) CustomAbort(status int, body string)
CustomAbort stops controller handler and show the error data, it's similar Aborts, but support status code and body.
func (*Controller) Delete ¶
func (c *Controller) Delete()
Delete adds a request function to handle DELETE request.
func (*Controller) Finish ¶
func (c *Controller) Finish()
Finish runs after request function execution.
func (*Controller) Get ¶
func (c *Controller) Get()
Get adds a request function to handle GET request.
func (*Controller) GetBool ¶
func (c *Controller) GetBool(key string, def ...bool) (bool, error)
GetBool returns input value as bool or the default value while it's present and input is blank.
func (*Controller) GetControllerAndAction ¶
func (c *Controller) GetControllerAndAction() (controllerName, actionName string)
GetControllerAndAction gets the executing controller name and action name.
func (*Controller) GetFile ¶
func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader, error)
GetFile returns the file data in file upload field named as key. it returns the first one of multi-uploaded files.
func (*Controller) GetFloat ¶
func (c *Controller) GetFloat(key string, def ...float64) (float64, error)
GetFloat returns input value as float64 or the default value while it's present and input is blank.
func (*Controller) GetInt ¶
func (c *Controller) GetInt(key string, def ...int) (int, error)
GetInt returns input as an int or the default value while it's present and input is blank
func (*Controller) GetInt16 ¶
func (c *Controller) GetInt16(key string, def ...int16) (int16, error)
GetInt16 returns input as an int16 or the default value while it's present and input is blank
func (*Controller) GetInt32 ¶
func (c *Controller) GetInt32(key string, def ...int32) (int32, error)
GetInt32 returns input as an int32 or the default value while it's present and input is blank
func (*Controller) GetInt64 ¶
func (c *Controller) GetInt64(key string, def ...int64) (int64, error)
GetInt64 returns input value as int64 or the default value while it's present and input is blank.
func (*Controller) GetInt8 ¶
func (c *Controller) GetInt8(key string, def ...int8) (int8, error)
GetInt8 return input as an int8 or the default value while it's present and input is blank
func (*Controller) GetSecureCookie ¶
func (c *Controller) GetSecureCookie(Secret, key string) (string, bool)
GetSecureCookie returns decoded cookie value from encoded browser cookie values.
func (*Controller) GetString ¶
func (c *Controller) GetString(key string, def ...string) string
GetString returns the input value by key string or the default value while it's present and input is blank
func (*Controller) GetStrings ¶
func (c *Controller) GetStrings(key string, def ...[]string) []string
GetStrings returns the input string slice by key string or the default value while it's present and input is blank it's designed for multi-value input field such as checkbox(input[type=checkbox]), multi-selection.
func (*Controller) HandlerFunc ¶
func (c *Controller) HandlerFunc(fnname string) bool
call function fn
func (*Controller) Head ¶
func (c *Controller) Head()
Head adds a request function to handle HEAD request.
func (*Controller) Init ¶
func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{})
Init generates default values of controller operations.
func (*Controller) Input ¶
func (c *Controller) Input() url.Values
Input returns the input data map from POST or PUT request body and query string.
func (*Controller) IsAjax ¶
func (c *Controller) IsAjax() bool
IsAjax returns this request is ajax or not.
func (*Controller) Mapping ¶
func (c *Controller) Mapping(method string, fn func())
func (*Controller) Options ¶
func (c *Controller) Options()
Options adds a request function to handle OPTIONS request.
func (*Controller) Patch ¶
func (c *Controller) Patch()
Patch adds a request function to handle PATCH request.
func (*Controller) Post ¶
func (c *Controller) Post()
Post adds a request function to handle POST request.
func (*Controller) Prepare ¶
func (c *Controller) Prepare()
Prepare runs after Init before request function execution.
func (*Controller) Put ¶
func (c *Controller) Put()
Put adds a request function to handle PUT request.
func (*Controller) RESTFaild ¶
func (c *Controller) RESTFaild(data interface{}, message interface{})
func (*Controller) RESTHeadCode ¶
func (c *Controller) RESTHeadCode(code int)
func (*Controller) RESTHeadNoContent ¶
func (c *Controller) RESTHeadNoContent()
func (*Controller) RESTHeadNotFound ¶
func (c *Controller) RESTHeadNotFound()
func (*Controller) RESTHeadSuccess ¶
func (c *Controller) RESTHeadSuccess()
func (*Controller) RESTJson ¶
func (c *Controller) RESTJson(code int, message string, data interface{})
func (*Controller) RESTSuccess ¶
func (c *Controller) RESTSuccess(data interface{}, message interface{})
func (*Controller) Redirect ¶
func (c *Controller) Redirect(url string, code int)
Redirect sends the redirection response to url with status code.
func (*Controller) Render ¶
func (c *Controller) Render() error
Render sends the response with rendered template bytes as text/html type.
func (*Controller) RenderBytes ¶
func (c *Controller) RenderBytes() ([]byte, error)
RenderBytes returns the bytes of rendered template string. Do not send out response.
func (*Controller) RenderString ¶
func (c *Controller) RenderString() (string, error)
RenderString returns the rendered template string. Do not send out response.
func (*Controller) SaveToFile ¶
func (c *Controller) SaveToFile(fromfile, tofile string) error
SaveToFile saves uploaded file to new path. it only operates the first one of mutil-upload form file field.
func (*Controller) ServeFormatted ¶
func (c *Controller) ServeFormatted()
ServeFormatted serve Xml OR Json, depending on the value of the Accept header
func (*Controller) ServeJson ¶
func (c *Controller) ServeJson(encoding ...bool)
ServeJson sends a json response with encoding charset.
func (*Controller) ServeJsonp ¶
func (c *Controller) ServeJsonp()
ServeJsonp sends a jsonp response.
func (*Controller) ServeString ¶
func (c *Controller) ServeString(data []byte)
ServeString sends a string response.
func (*Controller) SetSecureCookie ¶
func (c *Controller) SetSecureCookie(Secret, name, value string, others ...interface{})
SetSecureCookie puts value into cookie after encoded the value.
func (*Controller) StopRun ¶
func (c *Controller) StopRun()
StopRun makes panic of USERSTOPRUN error and go to recover function if defined.
func (*Controller) URLMapping ¶
func (c *Controller) URLMapping()
URLMapping register the internal Controller router.
func (*Controller) UrlFor ¶
func (c *Controller) UrlFor(endpoint string, values ...interface{}) string
UrlFor does another controller handler in this request function. it goes to this controller method if endpoint is not clear.
type ControllerComments ¶
type ControllerComments struct { Method string Router string AllowHTTPMethods []string Params []map[string]string }
store the comment for the controller method
type ControllerInterface ¶
type ControllerInterface interface { Init(ct *context.Context, controllerName, actionName string, app interface{}) Prepare() Get() Post() Delete() Put() Head() Patch() Options() Finish() Render() error HandlerFunc(fn string) bool URLMapping() }
ControllerInterface is an interface to uniform all controller handler.
type ControllerRegistor ¶
type ControllerRegistor struct {
// contains filtered or unexported fields
}
ControllerRegistor containers registered router rules, controller handlers and filters.
func NewControllerRegister ¶
func NewControllerRegister() *ControllerRegistor
NewControllerRegister returns a new ControllerRegistor.
func (*ControllerRegistor) Add ¶
func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingMethods ...string)
Add controller handler and pattern rules to ControllerRegistor. usage:
default methods is the same name as method Add("/user",&UserController{}) Add("/api/list",&RestController{},"*:ListFood") Add("/api/create",&RestController{},"post:CreateFood") Add("/api/update",&RestController{},"put:UpdateFood") Add("/api/delete",&RestController{},"delete:DeleteFood") Add("/api",&RestController{},"get,post:ApiFunc") Add("/simple",&SimpleController{},"get:GetFunc;post:PostFunc")
func (*ControllerRegistor) AddAuto ¶
func (p *ControllerRegistor) AddAuto(c ControllerInterface)
Add auto router to ControllerRegistor. example GoCrab.AddAuto(&MainContorlller{}), MainController has method List and Page. visit the url /main/list to execute List function /main/page to execute Page function.
func (*ControllerRegistor) AddAutoPrefix ¶
func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface)
Add auto router to ControllerRegistor with prefix. example GoCrab.AddAutoPrefix("/admin",&MainContorlller{}), MainController has method List and Page. visit the url /admin/main/list to execute List function /admin/main/page to execute Page function.
func (*ControllerRegistor) AddMethod ¶
func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc)
add http method router usage:
AddMethod("get","/api/:id", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func (*ControllerRegistor) Any ¶
func (p *ControllerRegistor) Any(pattern string, f FilterFunc)
add all method usage:
Any("/api/:id", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func (*ControllerRegistor) Delete ¶
func (p *ControllerRegistor) Delete(pattern string, f FilterFunc)
add delete method usage:
Delete("/api/:id", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func (*ControllerRegistor) Get ¶
func (p *ControllerRegistor) Get(pattern string, f FilterFunc)
add get method usage:
Get("/", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func (*ControllerRegistor) Handler ¶
func (p *ControllerRegistor) Handler(pattern string, h http.Handler, options ...interface{})
add user defined Handler
func (*ControllerRegistor) Head ¶
func (p *ControllerRegistor) Head(pattern string, f FilterFunc)
add head method usage:
Head("/api/:id", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func (*ControllerRegistor) Include ¶
func (p *ControllerRegistor) Include(cList ...ControllerInterface)
only when the Runmode is dev will generate router file in the router/auto.go from the controller Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})
func (*ControllerRegistor) InsertFilter ¶
func (p *ControllerRegistor) InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) error
Add a FilterFunc with pattern rule and action constant. The bool params is for setting the returnOnOutput value (false allows multiple filters to execute)
func (*ControllerRegistor) Options ¶
func (p *ControllerRegistor) Options(pattern string, f FilterFunc)
add options method usage:
Options("/api/:id", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func (*ControllerRegistor) Patch ¶
func (p *ControllerRegistor) Patch(pattern string, f FilterFunc)
add patch method usage:
Patch("/api/:id", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func (*ControllerRegistor) Post ¶
func (p *ControllerRegistor) Post(pattern string, f FilterFunc)
add post method usage:
Post("/api", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func (*ControllerRegistor) Put ¶
func (p *ControllerRegistor) Put(pattern string, f FilterFunc)
add put method usage:
Put("/api/:id", func(ctx *context.Context){ ctx.Output.Body("hello world") })
func (*ControllerRegistor) ServeHTTP ¶
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
Implement http.Handler interface.
func (*ControllerRegistor) UrlFor ¶
func (p *ControllerRegistor) UrlFor(endpoint string, values ...interface{}) string
UrlFor does another controller handler in this request function. it can access any controller method.
type FilterHandler ¶
var ( // supported http methods. HTTPMETHOD = map[string]string{ "GET": "GET", "POST": "POST", "PUT": "PUT", "DELETE": "DELETE", "PATCH": "PATCH", "OPTIONS": "OPTIONS", "HEAD": "HEAD", "TRACE": "TRACE", "CONNECT": "CONNECT", } DefaultLogFilter FilterHandler = &logFilter{} )
type FilterRouter ¶
type FilterRouter struct {
// contains filtered or unexported fields
}
FilterRouter defines filter operation before controller handler execution. it can match patterned url and do filter function when action arrives.
func (*FilterRouter) ValidRouter ¶
func (f *FilterRouter) ValidRouter(router string) (bool, map[string]string)
ValidRouter check current request is valid for this filter. if matched, returns parsed params in this request by defined filter router pattern.
type GoCrabAppConfig ¶
type GoCrabAppConfig struct {
// contains filtered or unexported fields
}
func (*GoCrabAppConfig) DIY ¶
func (b *GoCrabAppConfig) DIY(key string) (interface{}, error)
func (*GoCrabAppConfig) DefaultBool ¶
func (b *GoCrabAppConfig) DefaultBool(key string, defaultval bool) bool
func (*GoCrabAppConfig) DefaultFloat ¶
func (b *GoCrabAppConfig) DefaultFloat(key string, defaultval float64) float64
func (*GoCrabAppConfig) DefaultInt ¶
func (b *GoCrabAppConfig) DefaultInt(key string, defaultval int) int
func (*GoCrabAppConfig) DefaultInt64 ¶
func (b *GoCrabAppConfig) DefaultInt64(key string, defaultval int64) int64
func (*GoCrabAppConfig) DefaultString ¶
func (b *GoCrabAppConfig) DefaultString(key string, defaultval string) string
func (*GoCrabAppConfig) DefaultStrings ¶
func (b *GoCrabAppConfig) DefaultStrings(key string, defaultval []string) []string
func (*GoCrabAppConfig) GetSection ¶
func (b *GoCrabAppConfig) GetSection(section string) (map[string]string, error)
func (*GoCrabAppConfig) SaveConfigFile ¶
func (b *GoCrabAppConfig) SaveConfigFile(filename string) error
func (*GoCrabAppConfig) Set ¶
func (b *GoCrabAppConfig) Set(key, val string) error
func (*GoCrabAppConfig) String ¶
func (b *GoCrabAppConfig) String(key string) string
func (*GoCrabAppConfig) Strings ¶
func (b *GoCrabAppConfig) Strings(key string) []string