Documentation ¶
Overview ¶
reflect router
RESTful router
Index ¶
- Variables
- func CreateRESTfulController(routerKey string, controller interface{}) IRouter
- func CreateRESTfulControllerWithOption(routerKey string, controller interface{}, option RESTfulRouterOption) IRouter
- func CreateReflectController(routerKey string, controller interface{}) IRouter
- func CreateReflectControllerWithOption(routerKey string, controller interface{}, option ReflectRouterOption) IRouter
- type RESTfulController
- type RESTfulRouter
- func (r *RESTfulRouter) AfterRouterParse(context *HttpContext, option *RouterOption) HttpStatus
- func (r *RESTfulRouter) CallFunc(context *HttpContext, funcName string, option *RouterOption) (returnValue interface{}, statusCode HttpStatus, err error)
- func (r *RESTfulRouter) CallFuncAfter(context *HttpContext, option *RouterOption)
- func (r *RESTfulRouter) CallFuncBefore(context *HttpContext, option *RouterOption) HttpStatus
- func (r *RESTfulRouter) ControllerOption() ControllerOption
- func (r *RESTfulRouter) Info() string
- func (r *RESTfulRouter) ParseFuncName(context *HttpContext, option *RouterOption) (funcName string, statusCode HttpStatus, err error)
- func (r *RESTfulRouter) ParseTemplatePath(context *HttpContext, funcName string, option *RouterOption) string
- func (r *RESTfulRouter) RouterKey() string
- type RESTfulRouterOption
- type ReflectRouter
- func (r *ReflectRouter) AfterRouterParse(context *HttpContext, option *RouterOption) HttpStatus
- func (r *ReflectRouter) CallFunc(context *HttpContext, funcName string, option *RouterOption) (returnValue interface{}, statusCode HttpStatus, err error)
- func (r *ReflectRouter) CallFuncAfter(context *HttpContext, option *RouterOption)
- func (r *ReflectRouter) CallFuncBefore(context *HttpContext, option *RouterOption) HttpStatus
- func (r *ReflectRouter) ControllerOption() ControllerOption
- func (r *ReflectRouter) Info() string
- func (r *ReflectRouter) ParseFuncName(context *HttpContext, option *RouterOption) (funcName string, statusCode HttpStatus, err error)
- func (r *ReflectRouter) ParseTemplatePath(context *HttpContext, funcName string, option *RouterOption) string
- func (r *ReflectRouter) RouterKey() string
- type ReflectRouterOption
Constants ¶
This section is empty.
Variables ¶
View Source
var (
// controller default url request ("http://localhost:8080/") method
CONTROLLER_DEFAULT_METHOD = "Index"
)
Functions ¶
func CreateRESTfulController ¶
func CreateRESTfulController(routerKey string, controller interface{}) IRouter
*
- create RESTful router controller *
- @param routerKey "/" || "/home/" || "/admin/"
- @param controller
func CreateRESTfulControllerWithOption ¶
func CreateRESTfulControllerWithOption(routerKey string, controller interface{}, option RESTfulRouterOption) IRouter
*
- create RESTful router controller with option *
- @param option other params option
func CreateReflectController ¶
func CreateReflectController(routerKey string, controller interface{}) IRouter
*
- create reflect router controller *
- @param routerKey "/" || "/home/" || "/admin/"
- @param controller
func CreateReflectControllerWithOption ¶
func CreateReflectControllerWithOption(routerKey string, controller interface{}, option ReflectRouterOption) IRouter
*
- create reflect router controller with option *
- @param option other params option
Types ¶
type RESTfulController ¶
type RESTfulController interface { /** * method get * * @param context * @return handle return value see response_body.go */ Get(context *HttpContext) interface{} /** * method post * * @param context * @return */ Post(context *HttpContext) interface{} /** * method put * * @param context * @return */ Put(context *HttpContext) interface{} /** * method delete * * @param context * @return */ Delete(context *HttpContext) interface{} /** * method header * * @param context * @return */ Header(context *HttpContext) interface{} /** * method options * * @param context * @return */ Options(context *HttpContext) interface{} /** * other method * * @param context * @return */ Other(context *HttpContext) interface{} }
RESTful controller interface
type RESTfulRouter ¶
type RESTfulRouter struct {
// contains filtered or unexported fields
}
RESTful router
default template parh: [host]/[routerKey]/[funcNme].[TemplateSuffix]
"[host]/" multi-project use, lefveinServer.SetMultiProjectHosts("slowfei.com","svn.slowfei.com")
rule:
router key = "/api/object" URL = GET http://localhost:8080/api/object func name = get template path = [host]/api/object/get.tpl router key = "/api/object" URL = POST http://localhost:8080/api/object func name = post template path = [host]/api/object/post.tpl router key = "/api/object" URL = PUT http://localhost:8080/api/object func name = put template path = [host]/api/object/put.tpl router key = "/api/object" URL = DELETE http://localhost:8080/api/object func name = delete template path = [host]/api/object/delete.tpl
url params: implement AdeRouterController interface resolve on their own
控制器分的指针传递和值传递
值传递: CreateReflectController("/pointer/struct/", PointerController{}) 每次请求(http://localhost:8080/pointer/struct/) 都会根据设置的控制器类型新建立一个对象进行处理,直到一次请求周期结束。 指针传递: CreateReflectController("/pointer/", new(PointerController)) 跟值传递相反,每次请求时都会使用设置的控制器地址进行处理,应用结束也不会改变,每次请求控制器都不会改变内存地址 这里涉及到并发时同时使用一个内存地址处理的问题,使用时需要注意
func (*RESTfulRouter) AfterRouterParse ¶
func (r *RESTfulRouter) AfterRouterParse(context *HttpContext, option *RouterOption) HttpStatus
func (*RESTfulRouter) CallFunc ¶
func (r *RESTfulRouter) CallFunc(context *HttpContext, funcName string, option *RouterOption) (returnValue interface{}, statusCode HttpStatus, err error)
func (*RESTfulRouter) CallFuncAfter ¶
func (r *RESTfulRouter) CallFuncAfter(context *HttpContext, option *RouterOption)
func (*RESTfulRouter) CallFuncBefore ¶
func (r *RESTfulRouter) CallFuncBefore(context *HttpContext, option *RouterOption) HttpStatus
func (*RESTfulRouter) ControllerOption ¶
func (r *RESTfulRouter) ControllerOption() ControllerOption
func (*RESTfulRouter) Info ¶
func (r *RESTfulRouter) Info() string
func (*RESTfulRouter) ParseFuncName ¶
func (r *RESTfulRouter) ParseFuncName(context *HttpContext, option *RouterOption) (funcName string, statusCode HttpStatus, err error)
func (*RESTfulRouter) ParseTemplatePath ¶
func (r *RESTfulRouter) ParseTemplatePath(context *HttpContext, funcName string, option *RouterOption) string
func (*RESTfulRouter) RouterKey ¶
func (r *RESTfulRouter) RouterKey() string
type RESTfulRouterOption ¶
type RESTfulRouterOption struct {
ControllerOption
}
RESTful router option
func DefaultRESTfulRouterOption ¶
func DefaultRESTfulRouterOption() RESTfulRouterOption
*
- default option
func (RESTfulRouterOption) SetHost ¶
func (o RESTfulRouterOption) SetHost(host string) RESTfulRouterOption
*
- set host *
- "svn.slowfei.com" || "wwww.slowfei.com" || ""(wildcard)
func (RESTfulRouterOption) SetScheme ¶
func (o RESTfulRouterOption) SetScheme(scheme URIScheme) RESTfulRouterOption
*
- set the support scheme *
- URI_SCHEME_HTTP | URI_SCHEME_HTTPS
type ReflectRouter ¶
type ReflectRouter struct {
// contains filtered or unexported fields
}
reflect router
default template parh: [host]/[routerKey]/[funcNme].[TemplateSuffix]
"[host]/" multi-project use, lefveinServer.SetMultiProjectHosts("slowfei.com","svn.slowfei.com")
rule:
router key = "/" URL = GET http://localhost:8080/ func name = Index template path = [host]/Index.tpl router key = "/" URL = POST http://localhost:8080/ func name = PostIndex template path = [host]/PostIndex.tpl router key = "/" URL = Get http://localhost:8080/user#!list func name = UserList template path = [host]/UserList.tpl router key = "/" URL = Post http://localhost:8080/user[^a-zA-Z]+list[^a-zA-Z]+auto func name = PostUserListAuto template path = [host]/PostUserListAuto.tpl router key = "/admin/" URL = GET http://localhost:8080/admin/login func name = Login template path = [host]/admin/Login.tpl router key = "/admin/" URL = POST http://localhost:8080/admin/login func name = PostLogin template path = [host]/admin/PostLogin.tpl
控制器分的指针传递和值传递
值传递: CreateReflectController("/pointer/struct/", PointerController{}) 每次请求(http://localhost:8080/pointer/struct/) 都会根据设置的控制器类型新建立一个对象进行处理,直到一次请求周期结束。 指针传递: CreateReflectController("/pointer/", new(PointerController)) 跟值传递相反,每次请求时都会使用设置的控制器地址进行处理,应用结束也不会改变,每次请求控制器都不会改变内存地址 这里涉及到并发时同时使用一个内存地址处理的问题,使用时需要注意
func (*ReflectRouter) AfterRouterParse ¶
func (r *ReflectRouter) AfterRouterParse(context *HttpContext, option *RouterOption) HttpStatus
func (*ReflectRouter) CallFunc ¶
func (r *ReflectRouter) CallFunc(context *HttpContext, funcName string, option *RouterOption) (returnValue interface{}, statusCode HttpStatus, err error)
func (*ReflectRouter) CallFuncAfter ¶
func (r *ReflectRouter) CallFuncAfter(context *HttpContext, option *RouterOption)
func (*ReflectRouter) CallFuncBefore ¶
func (r *ReflectRouter) CallFuncBefore(context *HttpContext, option *RouterOption) HttpStatus
func (*ReflectRouter) ControllerOption ¶
func (r *ReflectRouter) ControllerOption() ControllerOption
func (*ReflectRouter) Info ¶
func (r *ReflectRouter) Info() string
func (*ReflectRouter) ParseFuncName ¶
func (r *ReflectRouter) ParseFuncName(context *HttpContext, option *RouterOption) (funcName string, statusCode HttpStatus, err error)
func (*ReflectRouter) ParseTemplatePath ¶
func (r *ReflectRouter) ParseTemplatePath(context *HttpContext, funcName string, option *RouterOption) string
func (*ReflectRouter) RouterKey ¶
func (r *ReflectRouter) RouterKey() string
type ReflectRouterOption ¶
type ReflectRouterOption struct {
ControllerOption
}
reflect router other option
func DefaultReflectRouterOption ¶
func DefaultReflectRouterOption() ReflectRouterOption
*
- default option
func (ReflectRouterOption) SetHost ¶
func (o ReflectRouterOption) SetHost(host string) ReflectRouterOption
*
- set host
- "svn.slowfei.com" || "wwww.slowfei.com" || ""(wildcard)
func (ReflectRouterOption) SetScheme ¶
func (o ReflectRouterOption) SetScheme(scheme URIScheme) ReflectRouterOption
*
- set the support scheme *
- URI_SCHEME_HTTP | URI_SCHEME_HTTPS
Click to show internal directories.
Click to hide internal directories.