Documentation
¶
Index ¶
- Constants
- Variables
- func GLogger() *logs.Logger
- func GetAlias(alias string) string
- func Run()
- func SetAlias(alias, path string)
- type ActionInfo
- type ActionInfoParam
- type Application
- func (app *Application) Arg(name string) string
- func (app *Application) BasePath() string
- func (app *Application) CmdMode() bool
- func (app *Application) Component(id string, funcName iface.IComponentFunc, params ...map[string]interface{}) interface{}
- func (app *Application) Config() config.IConfig
- func (app *Application) Container() *Container
- func (app *Application) Env() string
- func (app *Application) GetObjPool(name string, ctx iface.IContext, params ...interface{}) iface.IObject
- func (app *Application) GetObjSingle(name string, funcName iface.IObjSingleFunc, param ...interface{}) iface.IObject
- func (app *Application) HasArg(name string) bool
- func (app *Application) I18n() iface.II18n
- func (app *Application) Init(osArgs []string)
- func (app *Application) Log() *logs.Log
- func (app *Application) Mode() string
- func (app *Application) Name() string
- func (app *Application) PublicPath() string
- func (app *Application) Router() *Router
- func (app *Application) RuntimePath() string
- func (app *Application) Server() *Server
- func (app *Application) SetConfig(config config.IConfig)
- func (app *Application) SetI18n(i18n iface.II18n)
- func (app *Application) SetStatus(status iface.IStatus)
- func (app *Application) SetView(view iface.IView)
- func (app *Application) Status() iface.IStatus
- func (app *Application) StopBefore() *StopBefore
- func (app *Application) View() iface.IView
- func (app *Application) ViewPath() string
- type Container
- func (c *Container) Bind(i interface{}) string
- func (c *Container) Get(name string, ctx iface.IContext, params ...interface{}) reflect.Value
- func (c *Container) GetInfo(name string) interface{}
- func (c *Container) GetType(name string) reflect.Type
- func (c *Container) Has(name string) bool
- func (c *Container) PathList(prefix, suffix string) map[string]interface{}
- func (c *Container) Put(name string, rv reflect.Value)
- type Context
- func (c *Context) Abort()
- func (c *Context) ActionId() string
- func (c *Context) Cache(name string, rv reflect.Value)
- func (c *Context) ClientIp() string
- func (c *Context) ControllerId() string
- func (c *Context) Cookie(name, dft string) string
- func (c *Context) CookieAll() map[string]string
- func (c *Context) Copy() iface.IContext
- func (c *Context) Debug(format string, v ...interface{})
- func (c *Context) ElapseMs() int
- func (c *Context) End(status int, data []byte)
- func (c *Context) Error(format string, v ...interface{})
- func (c *Context) Fatal(format string, v ...interface{})
- func (c *Context) FinishGoLog()
- func (c *Context) Header(name, dft string) string
- func (c *Context) HeaderAll() map[string]string
- func (c *Context) HttpRW(debug, enableAccessLog bool, r *http.Request, w http.ResponseWriter)
- func (c *Context) Info(format string, v ...interface{})
- func (c *Context) Input() *http.Request
- func (c *Context) LogId() string
- func (c *Context) Method() string
- func (c *Context) Next()
- func (c *Context) Notice(format string, v ...interface{})
- func (c *Context) Output() http.ResponseWriter
- func (c *Context) Param(name, dft string) string
- func (c *Context) ParamAll() map[string]string
- func (c *Context) ParamArray(name string) []string
- func (c *Context) ParamMap(name string) map[string]string
- func (c *Context) Path() string
- func (c *Context) Post(name, dft string) string
- func (c *Context) PostAll() map[string]string
- func (c *Context) PostArray(name string) []string
- func (c *Context) PostMap(name string) map[string]string
- func (c *Context) Process(plugins []iface.IPlugin)
- func (c *Context) Query(name, dft string) string
- func (c *Context) QueryAll() map[string]string
- func (c *Context) QueryArray(name string) []string
- func (c *Context) QueryMap(name string) map[string]string
- func (c *Context) SetAccessLogFormat(v iface.IAccessLogFormat)
- func (c *Context) SetActionId(id string)
- func (c *Context) SetControllerId(id string)
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) SetEnableAccessLog(v bool)
- func (c *Context) SetHeader(name, value string)
- func (c *Context) SetInput(r *http.Request)
- func (c *Context) SetOutput(w http.ResponseWriter)
- func (c *Context) SetUserData(key string, data interface{})
- func (c *Context) Size() int
- func (c *Context) Start(plugins []iface.IPlugin)
- func (c *Context) Status() int
- func (c *Context) UserData(key string, dft interface{}) interface{}
- func (c *Context) ValidateParam(name string, dft ...interface{}) *validate.String
- func (c *Context) ValidatePost(name string, dft ...interface{}) *validate.String
- func (c *Context) ValidateQuery(name string, dft ...interface{}) *validate.String
- func (c *Context) Warn(format string, v ...interface{})
- type Controller
- func (c *Controller) AfterAction(action string)
- func (c *Controller) BeforeAction(action string)
- func (c *Controller) Data(data []byte, dftContentType ...string)
- func (c *Controller) Error(status int, message string)
- func (c *Controller) GetBindInfo(v interface{}) interface{}
- func (c *Controller) HandlePanic(v interface{}, debug bool)
- func (c *Controller) Json(data interface{}, status int, msg ...string)
- func (c *Controller) JsonV2(data interface{}, status int, msg ...string)
- func (c *Controller) Jsonp(callback string, data interface{}, status int, msg ...string)
- func (c *Controller) ProtoBuf(data interface{}, statuses ...int)
- func (c *Controller) Redirect(location string, permanent bool)
- func (c *Controller) Render(r render.Render, statuses ...int)
- func (c *Controller) SetActionDesc(message string)
- func (c *Controller) View(view string, data interface{}, contentTypes ...string)
- func (c *Controller) Xml(data interface{}, statuses ...int)
- type File
- type Gzip
- type Handler
- type I18n
- type Item
- type Object
- func (o *Object) Context() iface.IContext
- func (o *Object) GetObj(obj iface.IObject) iface.IObject
- func (o *Object) GetObjBox(className string, params ...interface{}) iface.IObject
- func (o *Object) GetObjBoxCtx(ctx iface.IContext, className string, params ...interface{}) iface.IObject
- func (o *Object) GetObjCtx(ctx iface.IContext, obj iface.IObject) iface.IObject
- func (o *Object) GetObjPool(className string, funcName iface.IObjPoolFunc, params ...interface{}) iface.IObject
- func (o *Object) GetObjPoolCtx(ctx iface.IContext, className string, funcName iface.IObjPoolFunc, ...) iface.IObject
- func (o *Object) GetObjSingle(name string, funcName iface.IObjSingleFunc, params ...interface{}) iface.IObject
- func (o *Object) GetObjSingleCtx(ctx iface.IContext, name string, funcName iface.IObjSingleFunc, ...) iface.IObject
- func (o *Object) SetContext(ctx iface.IContext)
- type Parser
- func (p *Parser) ActionInfo(pkgRealPath, pkgPath string) map[string][]*ActionInfo
- func (p *Parser) Dir(path string, filterFunc ...func(os.FileInfo) bool) map[string]*ast.Package
- func (p *Parser) GetActionInfo(pkgPath, controllerName, actionName string) *ActionInfo
- func (p *Parser) InitActionInfo(pkgRealPath, pkgPath string)
- func (p *Parser) ParseCallExpr(expr ast.Expr, pkgName string, minLenArg int) *ActionInfoParam
- type Response
- type Router
- func (r *Router) AddRoute(pattern, route string)
- func (r *Router) CmdHandlers() map[string]*Handler
- func (r *Router) CreateController(path string, ctx iface.IContext) (reflect.Value, reflect.Value, []string)
- func (r *Router) ErrorController(ctx iface.IContext, statuses ...int) iface.IController
- func (r *Router) Handler(path string) *Handler
- func (r *Router) InitHandlers()
- func (r *Router) Resolve(path, method string) (handler *Handler, params []string)
- func (r *Router) SetErrorController(v string)
- func (r *Router) SetHandlers(cmdType string, list map[string]interface{})
- func (r *Router) SetHttpStatus(v bool)
- func (r *Router) SetRules(rules []interface{})
- type Server
- func (s *Server) AddPlugin(v iface.IPlugin)
- func (s *Server) GetStats() *ServerStats
- func (s *Server) HandleRequest(ctx iface.IContext)
- func (s *Server) Serve()
- func (s *Server) ServeCMD()
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetAccessLogFormat(v iface.IAccessLogFormat)
- func (s *Server) SetCrtFile(certFile string)
- func (s *Server) SetDebug(v bool)
- func (s *Server) SetDebugAddr(addr string)
- func (s *Server) SetDisableCheckListen(v bool)
- func (s *Server) SetEnableAccessLog(v bool)
- func (s *Server) SetHttpAddr(addr string)
- func (s *Server) SetHttpsAddr(addr string)
- func (s *Server) SetKeyFile(keyFile string)
- func (s *Server) SetMaxHeaderBytes(maxBytes int)
- func (s *Server) SetMaxPostBodySize(maxBytes int64)
- func (s *Server) SetPlugins(v []interface{})
- func (s *Server) SetReadTimeout(v string)
- func (s *Server) SetStatsInterval(v string)
- func (s *Server) SetWriteTimeout(v string)
- type ServerConfig
- type ServerStats
- type Status
- type StopBefore
- type View
Constants ¶
const ( ModeWeb = "web" ModeCmd = "cmd" DefaultEnv = "develop" DefaultControllerPath = "index" DefaultActionPath = "index" DefaultHttpAddr = "0.0.0.0:8000" DefaultTimeout = 30 * time.Second DefaultHeaderBytes = 1 << 20 ControllerWebPkg = "controller" ControllerCmdPkg = "command" ControllerWebType = "Controller" ControllerCmdType = "Command" ConstructMethod = "Construct" PrepareMethod = "Prepare" VendorPrefix = "vendor/" VendorLength = 7 ActionPrefix = "Action" ActionLength = 6 TraceMaxDepth = 10 MaxPlugins = 32 MaxCacheObjects = 100 ParamsFlagMethodPrefix = "ParamsFlag" )
const (
EnablePoolOn = "on"
)
Variables ¶
var (
EmptyObject struct{}
)
Functions ¶
Types ¶
type ActionInfo ¶ added in v0.1.130
type ActionInfoParam ¶ added in v0.1.130
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
func App ¶
func App(newApp ...bool) *Application
func NewApp ¶
func NewApp() *Application
func (*Application) Arg ¶
func (app *Application) Arg(name string) string
func (*Application) BasePath ¶
func (app *Application) BasePath() string
BasePath base path, default is parent of executable
func (*Application) Component ¶
func (app *Application) Component(id string, funcName iface.IComponentFunc, params ...map[string]interface{}) interface{}
Get get component by id
func (*Application) Config ¶
func (app *Application) Config() config.IConfig
Config config component
func (*Application) Container ¶
func (app *Application) Container() *Container
Container container component
func (*Application) GetObjPool ¶
func (app *Application) GetObjPool(name string, ctx iface.IContext, params ...interface{}) iface.IObject
Get get pool class object. name is class name, ctx is context,
func (*Application) GetObjSingle ¶
func (app *Application) GetObjSingle(name string, funcName iface.IObjSingleFunc, param ...interface{}) iface.IObject
Get get single class object. name is class name, ctx is context,
func (*Application) HasArg ¶
func (app *Application) HasArg(name string) bool
func (*Application) Init ¶
func (app *Application) Init(osArgs []string)
func (*Application) Name ¶
func (app *Application) Name() string
Name appName, default is executable name
func (*Application) PublicPath ¶
func (app *Application) PublicPath() string
PublicPath public path, default is @app/public
func (*Application) RuntimePath ¶
func (app *Application) RuntimePath() string
RuntimePath runtime path, default is @app/runtime
func (*Application) SetConfig ¶
func (app *Application) SetConfig(config config.IConfig)
SetView set view component
func (*Application) SetI18n ¶
func (app *Application) SetI18n(i18n iface.II18n)
SetI18n set i18n component
func (*Application) SetStatus ¶
func (app *Application) SetStatus(status iface.IStatus)
SetStatus set status component
func (*Application) SetView ¶
func (app *Application) SetView(view iface.IView)
SetView set view component
func (*Application) StopBefore ¶
func (app *Application) StopBefore() *StopBefore
StopBefore stopBefore component
func (*Application) ViewPath ¶
func (app *Application) ViewPath() string
ViewPath view path, default is @app/view
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
func (*Container) Get ¶
Get get new class object. name is class name, config is properties map, params is optional construct parameters.
type Context ¶
Context pgo request context, context is not goroutine safe, copy context to use in other goroutines
func (*Context) ParamArray ¶
ParamArray get array value from GET/POST
func (*Context) QueryArray ¶
QueryArray get array value from GET
func (*Context) SetAccessLogFormat ¶ added in v0.1.9
func (c *Context) SetAccessLogFormat(v iface.IAccessLogFormat)
func (*Context) SetEnableAccessLog ¶ added in v0.1.114
func (*Context) SetUserData ¶
SetUserData set user data to current context
func (*Context) ValidateParam ¶
validate get/post param, return string validator
func (*Context) ValidatePost ¶
validate post param, return string validator
func (*Context) ValidateQuery ¶
validate query param, return string validator
type Controller ¶
type Controller struct {
Object
}
Controller the base class of web and cmd controller
func (*Controller) AfterAction ¶
func (c *Controller) AfterAction(action string)
AfterAction after action hook
func (*Controller) BeforeAction ¶
func (c *Controller) BeforeAction(action string)
BeforeAction before action hook
func (*Controller) Data ¶
func (c *Controller) Data(data []byte, dftContentType ...string)
Data output data response
func (*Controller) Error ¶ added in v0.1.1
func (c *Controller) Error(status int, message string)
Error
func (*Controller) GetBindInfo ¶
func (c *Controller) GetBindInfo(v interface{}) interface{}
GetBindInfo get action map as extra binding info
func (*Controller) HandlePanic ¶
func (c *Controller) HandlePanic(v interface{}, debug bool)
HandlePanic process unhandled action panic
func (*Controller) Json ¶
func (c *Controller) Json(data interface{}, status int, msg ...string)
Json output json response
func (*Controller) JsonV2 ¶ added in v0.1.132
func (c *Controller) JsonV2(data interface{}, status int, msg ...string)
JsonV2 output json response
func (*Controller) Jsonp ¶
func (c *Controller) Jsonp(callback string, data interface{}, status int, msg ...string)
Jsonp output jsonp response
func (*Controller) ProtoBuf ¶
func (c *Controller) ProtoBuf(data interface{}, statuses ...int)
ProtoBuf output proto buf response
func (*Controller) Redirect ¶
func (c *Controller) Redirect(location string, permanent bool)
Redirect output redirect response
func (*Controller) Render ¶
func (c *Controller) Render(r render.Render, statuses ...int)
Render Custom renderer
func (*Controller) SetActionDesc ¶ added in v0.1.122
func (c *Controller) SetActionDesc(message string)
SetActionDesc Deprecated: Delete the next version directly
func (*Controller) View ¶
func (c *Controller) View(view string, data interface{}, contentTypes ...string)
View output rendered view
func (*Controller) Xml ¶
func (c *Controller) Xml(data interface{}, statuses ...int)
Xml output xml response
type File ¶
type File struct {
// contains filtered or unexported fields
}
func NewFile ¶
File file plugin, this plugin only handle file in @public directory, request url with empty or excluded extension will not be handled.
func (*File) HandleRequest ¶
func (*File) SetExcludeExtensions ¶
func (f *File) SetExcludeExtensions(v []interface{})
type Gzip ¶
type Gzip struct {
// contains filtered or unexported fields
}
func (*Gzip) HandleRequest ¶
type I18n ¶
type I18n struct {
// contains filtered or unexported fields
}
func NewI18n ¶
I18n the internationalization component, language format is ll-CC or ll, lower case lang code, upper case area code. lang file name format is i18n_{lang}.json, and located in conf directory, configuration: i18n:
sourceLang: "en" targetLang: [ "en", "zh-CN", "zh-TW"]
func (*I18n) SetSourceLang ¶
SetSourceLang set language of source
func (*I18n) SetTargetLang ¶
func (i *I18n) SetTargetLang(targets []interface{})
SetTargetLang set language of target
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object base class of context based object
func (*Object) GetObjBox ¶ added in v0.1.116
GetObjPool Get Object from box,Have the function of the pool params: Parameter passed into Prepare
func (*Object) GetObjBoxCtx ¶ added in v0.1.116
func (o *Object) GetObjBoxCtx(ctx iface.IContext, className string, params ...interface{}) iface.IObject
GetObjBoxCtx Get Object from box and new Context,Have the function of the pool params: Parameter passed into Prepare
func (*Object) GetObjPool ¶
func (o *Object) GetObjPool(className string, funcName iface.IObjPoolFunc, params ...interface{}) iface.IObject
GetObjPool Get Object from pool Recommended: Use GetObjBox instead.
func (*Object) GetObjPoolCtx ¶
func (o *Object) GetObjPoolCtx(ctx iface.IContext, className string, funcName iface.IObjPoolFunc, params ...interface{}) iface.IObject
GetObjPoolCtx Get Object from pool and new Context Recommended: Use GetObjBoxCtx instead.
func (*Object) GetObjSingle ¶
func (o *Object) GetObjSingle(name string, funcName iface.IObjSingleFunc, params ...interface{}) iface.IObject
GetObject Get single object
func (*Object) GetObjSingleCtx ¶
func (o *Object) GetObjSingleCtx(ctx iface.IContext, name string, funcName iface.IObjSingleFunc, params ...interface{}) iface.IObject
GetObject Get single object and new Context
func (*Object) SetContext ¶
SetContext set context of this object
type Parser ¶ added in v0.1.130
type Parser struct { }
func (*Parser) ActionInfo ¶ added in v0.1.130
func (p *Parser) ActionInfo(pkgRealPath, pkgPath string) map[string][]*ActionInfo
func (*Parser) GetActionInfo ¶ added in v0.1.130
func (p *Parser) GetActionInfo(pkgPath, controllerName, actionName string) *ActionInfo
func (*Parser) InitActionInfo ¶ added in v0.1.130
func (*Parser) ParseCallExpr ¶ added in v0.1.130
type Response ¶
type Response struct { http.ResponseWriter // contains filtered or unexported fields }
Response http.ResponseWriter wrapper
func (*Response) ReadFrom ¶
ReadFrom is here to optimize copying from a regular file to a *net.TCPConn with sendfile.
func (*Response) Write ¶
Write write data to underlying http.ResponseWriter and record num bytes that has written.
func (*Response) WriteHeader ¶
WriteHeader cache status code until first write operation.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func NewRouter ¶
Router the router component, configuration: router:
httpStatus:true // Whether to override the HTTP status code rules: - "^/foo/all$ => /foo/index" - "^/api/user/(\d+)$ => /api/user"
func (*Router) AddRoute ¶
AddRoute add one route, the captured group will be passed to action method as function params
func (*Router) CmdHandlers ¶
func (*Router) CreateController ¶
func (r *Router) CreateController(path string, ctx iface.IContext) (reflect.Value, reflect.Value, []string)
CreateController Create the controller and parameters
func (*Router) ErrorController ¶ added in v0.1.1
func (*Router) SetErrorController ¶ added in v0.1.1
func (*Router) SetHandlers ¶
SetHandlers Set route
func (*Router) SetHttpStatus ¶ added in v0.1.1
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
Server the server component, configuration: server:
httpAddr: "0.0.0.0:8000" debugAddr: "0.0.0.0:8100" httpsAddr: "0.0.0.0:8443" crtFile: "@app/conf/site.crt" keyFile: "@app/conf/site.key" maxHeaderBytes: 1048576 readTimeout: "30s" writeTimeout: "30s" statsInterval: "60s" enableAccessLog: true maxPostBodySize: 1048576 debug:true disableCheckListen: true
func (*Server) HandleRequest ¶
HandleRequest handle request of cmd or http, this method called in the last of plugin chain.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serve http request
func (*Server) SetAccessLogFormat ¶ added in v0.1.9
func (s *Server) SetAccessLogFormat(v iface.IAccessLogFormat)
SetAccessLogFormat set accessLogFormat
func (*Server) SetCrtFile ¶
SetCrtFile set certificate file for https
func (*Server) SetDebugAddr ¶
SetDebugAddr set debug and pprof addr.
func (*Server) SetDisableCheckListen ¶ added in v0.1.127
SetDisableCheckListen Disable check listen port
func (*Server) SetEnableAccessLog ¶
SetEnableAccessLog set access log enable or not
func (*Server) SetHttpAddr ¶
SetHttpAddr set http addr, if both httpAddr and httpsAddr are empty, "0.0.0.0:8000" will be used as httpAddr.
func (*Server) SetHttpsAddr ¶
SetHttpsAddr set https addr.
func (*Server) SetKeyFile ¶
SetKeyFile set private key file for https
func (*Server) SetMaxHeaderBytes ¶
SetMaxHeaderBytes set max header bytes
func (*Server) SetMaxPostBodySize ¶
SetMaxPostBodySize set max header bytes
func (*Server) SetPlugins ¶
func (s *Server) SetPlugins(v []interface{})
SetPlugins set plugin by names
func (*Server) SetReadTimeout ¶
SetReadTimeout set timeout to read request
func (*Server) SetStatsInterval ¶
SetStatsInterval set interval to output stats
func (*Server) SetWriteTimeout ¶
SetWriteTimeout set timeout to write response
type ServerConfig ¶
type ServerConfig struct {
// contains filtered or unexported fields
}
type ServerStats ¶
type ServerStats struct { MemMB uint // memory obtained from os NumReq uint64 // number of handled requests NumGO uint // number of goroutines NumGC uint // number of gc runs TimeGC string // total time of gc pause TimeRun string // total time of app runs }
ServerStats server stats
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
func NewStatus ¶
Status the status component, configuration: status:
useI18n: false mapping: 11002: "Verify Sign Error"
func (*Status) SetMapping ¶
SetMapping set mapping from status code to text
func (*Status) SetUseI18n ¶
SetUseI18n set whether to use i18n translation
type StopBefore ¶
type StopBefore struct {
// contains filtered or unexported fields
}
func NewStopBefore ¶
func NewStopBefore() *StopBefore
func (*StopBefore) Add ¶
func (s *StopBefore) Add(obj interface{}, method string, dfParams ...interface{})
增加停止前执行的对象和方法
type View ¶
type View struct {
// contains filtered or unexported fields
}
func NewView ¶
View the view component, configuration: view:
suffix: ".html" commons: - "@view/common/header.html" - "@view/common/footer.html"
func (*View) AddFuncMap ¶
AddFuncMap add custom func map
func (*View) SetCommons ¶
func (v *View) SetCommons(commons []interface{})
SetCommons set common view files
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
client
|
|
test
|
|
mock/adapter
Package mock_adapter is a generated GoMock package.
|
Package mock_adapter is a generated GoMock package. |
mock/config
Package mock_config is a generated GoMock package.
|
Package mock_config is a generated GoMock package. |
mock/iface
Package mock_iface is a generated GoMock package.
|
Package mock_iface is a generated GoMock package. |
mock/logs
Package mock_logs is a generated GoMock package.
|
Package mock_logs is a generated GoMock package. |
mock/render
Package mock_render is a generated GoMock package.
|
Package mock_render is a generated GoMock package. |