mirror of
https://github.com/astaxie/beego.git
synced 2024-11-21 20:20:55 +00:00
Deprecated old web module
This commit is contained in:
parent
02972d8702
commit
882aa9b967
3
admin.go
3
admin.go
@ -52,6 +52,7 @@ var beeAdminApp *adminApp
|
|||||||
// return true
|
// return true
|
||||||
// }
|
// }
|
||||||
// beego.FilterMonitorFunc = MyFilterMonitor.
|
// beego.FilterMonitorFunc = MyFilterMonitor.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
var FilterMonitorFunc func(string, string, time.Duration, string, int) bool
|
var FilterMonitorFunc func(string, string, time.Duration, string, int) bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -201,6 +202,7 @@ func list(root string, p interface{}, m M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PrintTree prints all registered routers.
|
// PrintTree prints all registered routers.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func PrintTree() M {
|
func PrintTree() M {
|
||||||
var (
|
var (
|
||||||
content = M{}
|
content = M{}
|
||||||
@ -432,6 +434,7 @@ func (admin *adminApp) Route(pattern string, f http.HandlerFunc) {
|
|||||||
|
|
||||||
// Run adminApp http server.
|
// Run adminApp http server.
|
||||||
// Its addr is defined in configuration file as adminhttpaddr and adminhttpport.
|
// Its addr is defined in configuration file as adminhttpaddr and adminhttpport.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (admin *adminApp) Run() {
|
func (admin *adminApp) Run() {
|
||||||
if len(toolbox.AdminTaskList) > 0 {
|
if len(toolbox.AdminTaskList) > 0 {
|
||||||
toolbox.StartTask()
|
toolbox.StartTask()
|
||||||
|
20
app.go
20
app.go
@ -35,6 +35,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// BeeApp is an application instance
|
// BeeApp is an application instance
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
BeeApp *App
|
BeeApp *App
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -50,6 +51,7 @@ type App struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewApp returns a new beego application.
|
// NewApp returns a new beego application.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NewApp() *App {
|
func NewApp() *App {
|
||||||
cr := NewControllerRegister()
|
cr := NewControllerRegister()
|
||||||
app := &App{Handlers: cr, Server: &http.Server{}}
|
app := &App{Handlers: cr, Server: &http.Server{}}
|
||||||
@ -57,9 +59,11 @@ func NewApp() *App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MiddleWare function for http.Handler
|
// MiddleWare function for http.Handler
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type MiddleWare func(http.Handler) http.Handler
|
type MiddleWare func(http.Handler) http.Handler
|
||||||
|
|
||||||
// Run beego application.
|
// Run beego application.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (app *App) Run(mws ...MiddleWare) {
|
func (app *App) Run(mws ...MiddleWare) {
|
||||||
addr := BConfig.Listen.HTTPAddr
|
addr := BConfig.Listen.HTTPAddr
|
||||||
|
|
||||||
@ -254,6 +258,7 @@ func (app *App) Run(mws ...MiddleWare) {
|
|||||||
// beego.Router("/api/create",&RestController{},"post:CreateFood")
|
// beego.Router("/api/create",&RestController{},"post:CreateFood")
|
||||||
// beego.Router("/api/update",&RestController{},"put:UpdateFood")
|
// beego.Router("/api/update",&RestController{},"put:UpdateFood")
|
||||||
// beego.Router("/api/delete",&RestController{},"delete:DeleteFood")
|
// beego.Router("/api/delete",&RestController{},"delete:DeleteFood")
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *App {
|
func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *App {
|
||||||
BeeApp.Handlers.Add(rootpath, c, mappingMethods...)
|
BeeApp.Handlers.Add(rootpath, c, mappingMethods...)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -268,6 +273,7 @@ func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *A
|
|||||||
// Usage (replace "GET" with "*" for all methods):
|
// Usage (replace "GET" with "*" for all methods):
|
||||||
// beego.UnregisterFixedRoute("/yourpreviouspath", "GET")
|
// beego.UnregisterFixedRoute("/yourpreviouspath", "GET")
|
||||||
// beego.Router("/yourpreviouspath", yourControllerAddress, "get:GetNewPage")
|
// beego.Router("/yourpreviouspath", yourControllerAddress, "get:GetNewPage")
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func UnregisterFixedRoute(fixedRoute string, method string) *App {
|
func UnregisterFixedRoute(fixedRoute string, method string) *App {
|
||||||
subPaths := splitPath(fixedRoute)
|
subPaths := splitPath(fixedRoute)
|
||||||
if method == "" || method == "*" {
|
if method == "" || method == "*" {
|
||||||
@ -364,6 +370,7 @@ func findAndRemoveSingleTree(entryPointTree *Tree) {
|
|||||||
// the comments @router url methodlist
|
// the comments @router url methodlist
|
||||||
// url support all the function Router's pattern
|
// url support all the function Router's pattern
|
||||||
// methodlist [get post head put delete options *]
|
// methodlist [get post head put delete options *]
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Include(cList ...ControllerInterface) *App {
|
func Include(cList ...ControllerInterface) *App {
|
||||||
BeeApp.Handlers.Include(cList...)
|
BeeApp.Handlers.Include(cList...)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -372,6 +379,7 @@ func Include(cList ...ControllerInterface) *App {
|
|||||||
// RESTRouter adds a restful controller handler to BeeApp.
|
// RESTRouter adds a restful controller handler to BeeApp.
|
||||||
// its' controller implements beego.ControllerInterface and
|
// its' controller implements beego.ControllerInterface and
|
||||||
// defines a param "pattern/:objectId" to visit each resource.
|
// defines a param "pattern/:objectId" to visit each resource.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func RESTRouter(rootpath string, c ControllerInterface) *App {
|
func RESTRouter(rootpath string, c ControllerInterface) *App {
|
||||||
Router(rootpath, c)
|
Router(rootpath, c)
|
||||||
Router(path.Join(rootpath, ":objectId"), c)
|
Router(path.Join(rootpath, ":objectId"), c)
|
||||||
@ -382,6 +390,7 @@ func RESTRouter(rootpath string, c ControllerInterface) *App {
|
|||||||
// it's same to App.AutoRouter.
|
// it's same to App.AutoRouter.
|
||||||
// if beego.AddAuto(&MainContorlller{}) and MainController has methods List and Page,
|
// if beego.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.
|
// visit the url /main/list to exec List function or /main/page to exec Page function.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func AutoRouter(c ControllerInterface) *App {
|
func AutoRouter(c ControllerInterface) *App {
|
||||||
BeeApp.Handlers.AddAuto(c)
|
BeeApp.Handlers.AddAuto(c)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -391,6 +400,7 @@ func AutoRouter(c ControllerInterface) *App {
|
|||||||
// it's same to App.AutoRouterWithPrefix.
|
// it's same to App.AutoRouterWithPrefix.
|
||||||
// if beego.AutoPrefix("/admin",&MainContorlller{}) and MainController has methods List and Page,
|
// if beego.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.
|
// visit the url /admin/main/list to exec List function or /admin/main/page to exec Page function.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func AutoPrefix(prefix string, c ControllerInterface) *App {
|
func AutoPrefix(prefix string, c ControllerInterface) *App {
|
||||||
BeeApp.Handlers.AddAutoPrefix(prefix, c)
|
BeeApp.Handlers.AddAutoPrefix(prefix, c)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -401,6 +411,7 @@ func AutoPrefix(prefix string, c ControllerInterface) *App {
|
|||||||
// beego.Get("/", func(ctx *context.Context){
|
// beego.Get("/", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Get(rootpath string, f FilterFunc) *App {
|
func Get(rootpath string, f FilterFunc) *App {
|
||||||
BeeApp.Handlers.Get(rootpath, f)
|
BeeApp.Handlers.Get(rootpath, f)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -411,6 +422,7 @@ func Get(rootpath string, f FilterFunc) *App {
|
|||||||
// beego.Post("/api", func(ctx *context.Context){
|
// beego.Post("/api", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Post(rootpath string, f FilterFunc) *App {
|
func Post(rootpath string, f FilterFunc) *App {
|
||||||
BeeApp.Handlers.Post(rootpath, f)
|
BeeApp.Handlers.Post(rootpath, f)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -421,6 +433,7 @@ func Post(rootpath string, f FilterFunc) *App {
|
|||||||
// beego.Delete("/api", func(ctx *context.Context){
|
// beego.Delete("/api", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Delete(rootpath string, f FilterFunc) *App {
|
func Delete(rootpath string, f FilterFunc) *App {
|
||||||
BeeApp.Handlers.Delete(rootpath, f)
|
BeeApp.Handlers.Delete(rootpath, f)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -431,6 +444,7 @@ func Delete(rootpath string, f FilterFunc) *App {
|
|||||||
// beego.Put("/api", func(ctx *context.Context){
|
// beego.Put("/api", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Put(rootpath string, f FilterFunc) *App {
|
func Put(rootpath string, f FilterFunc) *App {
|
||||||
BeeApp.Handlers.Put(rootpath, f)
|
BeeApp.Handlers.Put(rootpath, f)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -441,6 +455,7 @@ func Put(rootpath string, f FilterFunc) *App {
|
|||||||
// beego.Head("/api", func(ctx *context.Context){
|
// beego.Head("/api", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Head(rootpath string, f FilterFunc) *App {
|
func Head(rootpath string, f FilterFunc) *App {
|
||||||
BeeApp.Handlers.Head(rootpath, f)
|
BeeApp.Handlers.Head(rootpath, f)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -451,6 +466,7 @@ func Head(rootpath string, f FilterFunc) *App {
|
|||||||
// beego.Options("/api", func(ctx *context.Context){
|
// beego.Options("/api", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Options(rootpath string, f FilterFunc) *App {
|
func Options(rootpath string, f FilterFunc) *App {
|
||||||
BeeApp.Handlers.Options(rootpath, f)
|
BeeApp.Handlers.Options(rootpath, f)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -461,6 +477,7 @@ func Options(rootpath string, f FilterFunc) *App {
|
|||||||
// beego.Patch("/api", func(ctx *context.Context){
|
// beego.Patch("/api", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Patch(rootpath string, f FilterFunc) *App {
|
func Patch(rootpath string, f FilterFunc) *App {
|
||||||
BeeApp.Handlers.Patch(rootpath, f)
|
BeeApp.Handlers.Patch(rootpath, f)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -471,6 +488,7 @@ func Patch(rootpath string, f FilterFunc) *App {
|
|||||||
// beego.Any("/api", func(ctx *context.Context){
|
// beego.Any("/api", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Any(rootpath string, f FilterFunc) *App {
|
func Any(rootpath string, f FilterFunc) *App {
|
||||||
BeeApp.Handlers.Any(rootpath, f)
|
BeeApp.Handlers.Any(rootpath, f)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -481,6 +499,7 @@ func Any(rootpath string, f FilterFunc) *App {
|
|||||||
// beego.Handler("/api", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
|
// beego.Handler("/api", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
|
||||||
// fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
// fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
||||||
// }))
|
// }))
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Handler(rootpath string, h http.Handler, options ...interface{}) *App {
|
func Handler(rootpath string, h http.Handler, options ...interface{}) *App {
|
||||||
BeeApp.Handlers.Handler(rootpath, h, options...)
|
BeeApp.Handlers.Handler(rootpath, h, options...)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -490,6 +509,7 @@ func Handler(rootpath string, h http.Handler, options ...interface{}) *App {
|
|||||||
// The pos means action constant including
|
// The pos means action constant including
|
||||||
// beego.BeforeStatic, beego.BeforeRouter, beego.BeforeExec, beego.AfterExec and beego.FinishRouter.
|
// beego.BeforeStatic, beego.BeforeRouter, beego.BeforeExec, beego.AfterExec and beego.FinishRouter.
|
||||||
// The bool params is for setting the returnOnOutput value (false allows multiple filters to execute)
|
// The bool params is for setting the returnOnOutput value (false allows multiple filters to execute)
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) *App {
|
func InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) *App {
|
||||||
BeeApp.Handlers.InsertFilter(pattern, pos, filter, params...)
|
BeeApp.Handlers.InsertFilter(pattern, pos, filter, params...)
|
||||||
return BeeApp
|
return BeeApp
|
||||||
|
9
beego.go
9
beego.go
@ -23,15 +23,19 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// VERSION represent beego web framework version.
|
// VERSION represent beego web framework version.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
VERSION = "1.12.2"
|
VERSION = "1.12.2"
|
||||||
|
|
||||||
// DEV is for develop
|
// DEV is for develop
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
DEV = "dev"
|
DEV = "dev"
|
||||||
// PROD is for production
|
// PROD is for production
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
PROD = "prod"
|
PROD = "prod"
|
||||||
)
|
)
|
||||||
|
|
||||||
// M is Map shortcut
|
// M is Map shortcut
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type M map[string]interface{}
|
type M map[string]interface{}
|
||||||
|
|
||||||
// Hook function to run
|
// Hook function to run
|
||||||
@ -44,6 +48,7 @@ var (
|
|||||||
// AddAPPStartHook is used to register the hookfunc
|
// AddAPPStartHook is used to register the hookfunc
|
||||||
// The hookfuncs will run in beego.Run()
|
// The hookfuncs will run in beego.Run()
|
||||||
// such as initiating session , starting middleware , building template, starting admin control and so on.
|
// such as initiating session , starting middleware , building template, starting admin control and so on.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func AddAPPStartHook(hf ...hookfunc) {
|
func AddAPPStartHook(hf ...hookfunc) {
|
||||||
hooks = append(hooks, hf...)
|
hooks = append(hooks, hf...)
|
||||||
}
|
}
|
||||||
@ -53,6 +58,7 @@ func AddAPPStartHook(hf ...hookfunc) {
|
|||||||
// beego.Run("localhost")
|
// beego.Run("localhost")
|
||||||
// beego.Run(":8089")
|
// beego.Run(":8089")
|
||||||
// beego.Run("127.0.0.1:8089")
|
// beego.Run("127.0.0.1:8089")
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Run(params ...string) {
|
func Run(params ...string) {
|
||||||
|
|
||||||
initBeforeHTTPRun()
|
initBeforeHTTPRun()
|
||||||
@ -73,6 +79,7 @@ func Run(params ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunWithMiddleWares Run beego application with middlewares.
|
// RunWithMiddleWares Run beego application with middlewares.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func RunWithMiddleWares(addr string, mws ...MiddleWare) {
|
func RunWithMiddleWares(addr string, mws ...MiddleWare) {
|
||||||
initBeforeHTTPRun()
|
initBeforeHTTPRun()
|
||||||
|
|
||||||
@ -107,6 +114,7 @@ func initBeforeHTTPRun() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TestBeegoInit is for test package init
|
// TestBeegoInit is for test package init
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func TestBeegoInit(ap string) {
|
func TestBeegoInit(ap string) {
|
||||||
path := filepath.Join(ap, "conf", "app.conf")
|
path := filepath.Join(ap, "conf", "app.conf")
|
||||||
os.Chdir(ap)
|
os.Chdir(ap)
|
||||||
@ -114,6 +122,7 @@ func TestBeegoInit(ap string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InitBeegoBeforeTest is for test package init
|
// InitBeegoBeforeTest is for test package init
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func InitBeegoBeforeTest(appConfigPath string) {
|
func InitBeegoBeforeTest(appConfigPath string) {
|
||||||
if err := LoadAppConfig(appConfigProvider, appConfigPath); err != nil {
|
if err := LoadAppConfig(appConfigProvider, appConfigPath); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -15,13 +15,20 @@
|
|||||||
package beego
|
package beego
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
BuildVersion string
|
BuildVersion string
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
BuildGitRevision string
|
BuildGitRevision string
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
BuildStatus string
|
BuildStatus string
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
BuildTag string
|
BuildTag string
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
BuildTime string
|
BuildTime string
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
GoVersion string
|
GoVersion string
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
GitBranch string
|
GitBranch string
|
||||||
)
|
)
|
||||||
|
27
config.go
27
config.go
@ -31,6 +31,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Config is the main struct for BConfig
|
// Config is the main struct for BConfig
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AppName string //Application name
|
AppName string //Application name
|
||||||
RunMode string //Running Mode: dev | prod
|
RunMode string //Running Mode: dev | prod
|
||||||
@ -49,6 +50,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Listen holds for http and https related config
|
// Listen holds for http and https related config
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type Listen struct {
|
type Listen struct {
|
||||||
Graceful bool // Graceful means use graceful module to start the server
|
Graceful bool // Graceful means use graceful module to start the server
|
||||||
ServerTimeOut int64
|
ServerTimeOut int64
|
||||||
@ -75,6 +77,7 @@ type Listen struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WebConfig holds web related config
|
// WebConfig holds web related config
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type WebConfig struct {
|
type WebConfig struct {
|
||||||
AutoRender bool
|
AutoRender bool
|
||||||
EnableDocs bool
|
EnableDocs bool
|
||||||
@ -95,6 +98,7 @@ type WebConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SessionConfig holds session related config
|
// SessionConfig holds session related config
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type SessionConfig struct {
|
type SessionConfig struct {
|
||||||
SessionOn bool
|
SessionOn bool
|
||||||
SessionProvider string
|
SessionProvider string
|
||||||
@ -111,6 +115,7 @@ type SessionConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LogConfig holds Log related config
|
// LogConfig holds Log related config
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type LogConfig struct {
|
type LogConfig struct {
|
||||||
AccessLogs bool
|
AccessLogs bool
|
||||||
EnableStaticLogs bool //log static files requests default: false
|
EnableStaticLogs bool //log static files requests default: false
|
||||||
@ -121,12 +126,16 @@ type LogConfig struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// BConfig is the default config for Application
|
// BConfig is the default config for Application
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
BConfig *Config
|
BConfig *Config
|
||||||
// AppConfig is the instance of Config, store the config information from file
|
// AppConfig is the instance of Config, store the config information from file
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
AppConfig *beegoAppConfig
|
AppConfig *beegoAppConfig
|
||||||
// AppPath is the absolute path to the app
|
// AppPath is the absolute path to the app
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
AppPath string
|
AppPath string
|
||||||
// GlobalSessions is the instance for the session manager
|
// GlobalSessions is the instance for the session manager
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
GlobalSessions *session.Manager
|
GlobalSessions *session.Manager
|
||||||
|
|
||||||
// appConfigPath is the path to the config files
|
// appConfigPath is the path to the config files
|
||||||
@ -134,6 +143,7 @@ var (
|
|||||||
// appConfigProvider is the provider for the config, default is ini
|
// appConfigProvider is the provider for the config, default is ini
|
||||||
appConfigProvider = "ini"
|
appConfigProvider = "ini"
|
||||||
// WorkPath is the absolute path to project root directory
|
// WorkPath is the absolute path to project root directory
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
WorkPath string
|
WorkPath string
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -398,6 +408,7 @@ func assignSingleConfig(p interface{}, ac config.Configer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadAppConfig allow developer to apply a config file
|
// LoadAppConfig allow developer to apply a config file
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func LoadAppConfig(adapterName, configPath string) error {
|
func LoadAppConfig(adapterName, configPath string) error {
|
||||||
absConfigPath, err := filepath.Abs(configPath)
|
absConfigPath, err := filepath.Abs(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -426,6 +437,7 @@ func newAppConfig(appConfigProvider, appConfigPath string) (*beegoAppConfig, err
|
|||||||
return &beegoAppConfig{ac}, nil
|
return &beegoAppConfig{ac}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) Set(key, val string) error {
|
func (b *beegoAppConfig) Set(key, val string) error {
|
||||||
if err := b.innerConfig.Set(BConfig.RunMode+"::"+key, val); err != nil {
|
if err := b.innerConfig.Set(BConfig.RunMode+"::"+key, val); err != nil {
|
||||||
return b.innerConfig.Set(key, val)
|
return b.innerConfig.Set(key, val)
|
||||||
@ -433,6 +445,7 @@ func (b *beegoAppConfig) Set(key, val string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) String(key string) string {
|
func (b *beegoAppConfig) String(key string) string {
|
||||||
if v := b.innerConfig.String(BConfig.RunMode + "::" + key); v != "" {
|
if v := b.innerConfig.String(BConfig.RunMode + "::" + key); v != "" {
|
||||||
return v
|
return v
|
||||||
@ -440,6 +453,7 @@ func (b *beegoAppConfig) String(key string) string {
|
|||||||
return b.innerConfig.String(key)
|
return b.innerConfig.String(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) Strings(key string) []string {
|
func (b *beegoAppConfig) Strings(key string) []string {
|
||||||
if v := b.innerConfig.Strings(BConfig.RunMode + "::" + key); len(v) > 0 {
|
if v := b.innerConfig.Strings(BConfig.RunMode + "::" + key); len(v) > 0 {
|
||||||
return v
|
return v
|
||||||
@ -447,6 +461,7 @@ func (b *beegoAppConfig) Strings(key string) []string {
|
|||||||
return b.innerConfig.Strings(key)
|
return b.innerConfig.Strings(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) Int(key string) (int, error) {
|
func (b *beegoAppConfig) Int(key string) (int, error) {
|
||||||
if v, err := b.innerConfig.Int(BConfig.RunMode + "::" + key); err == nil {
|
if v, err := b.innerConfig.Int(BConfig.RunMode + "::" + key); err == nil {
|
||||||
return v, nil
|
return v, nil
|
||||||
@ -454,6 +469,7 @@ func (b *beegoAppConfig) Int(key string) (int, error) {
|
|||||||
return b.innerConfig.Int(key)
|
return b.innerConfig.Int(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) Int64(key string) (int64, error) {
|
func (b *beegoAppConfig) Int64(key string) (int64, error) {
|
||||||
if v, err := b.innerConfig.Int64(BConfig.RunMode + "::" + key); err == nil {
|
if v, err := b.innerConfig.Int64(BConfig.RunMode + "::" + key); err == nil {
|
||||||
return v, nil
|
return v, nil
|
||||||
@ -461,6 +477,7 @@ func (b *beegoAppConfig) Int64(key string) (int64, error) {
|
|||||||
return b.innerConfig.Int64(key)
|
return b.innerConfig.Int64(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) Bool(key string) (bool, error) {
|
func (b *beegoAppConfig) Bool(key string) (bool, error) {
|
||||||
if v, err := b.innerConfig.Bool(BConfig.RunMode + "::" + key); err == nil {
|
if v, err := b.innerConfig.Bool(BConfig.RunMode + "::" + key); err == nil {
|
||||||
return v, nil
|
return v, nil
|
||||||
@ -468,6 +485,7 @@ func (b *beegoAppConfig) Bool(key string) (bool, error) {
|
|||||||
return b.innerConfig.Bool(key)
|
return b.innerConfig.Bool(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) Float(key string) (float64, error) {
|
func (b *beegoAppConfig) Float(key string) (float64, error) {
|
||||||
if v, err := b.innerConfig.Float(BConfig.RunMode + "::" + key); err == nil {
|
if v, err := b.innerConfig.Float(BConfig.RunMode + "::" + key); err == nil {
|
||||||
return v, nil
|
return v, nil
|
||||||
@ -475,6 +493,7 @@ func (b *beegoAppConfig) Float(key string) (float64, error) {
|
|||||||
return b.innerConfig.Float(key)
|
return b.innerConfig.Float(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) DefaultString(key string, defaultVal string) string {
|
func (b *beegoAppConfig) DefaultString(key string, defaultVal string) string {
|
||||||
if v := b.String(key); v != "" {
|
if v := b.String(key); v != "" {
|
||||||
return v
|
return v
|
||||||
@ -482,6 +501,7 @@ func (b *beegoAppConfig) DefaultString(key string, defaultVal string) string {
|
|||||||
return defaultVal
|
return defaultVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) DefaultStrings(key string, defaultVal []string) []string {
|
func (b *beegoAppConfig) DefaultStrings(key string, defaultVal []string) []string {
|
||||||
if v := b.Strings(key); len(v) != 0 {
|
if v := b.Strings(key); len(v) != 0 {
|
||||||
return v
|
return v
|
||||||
@ -489,6 +509,7 @@ func (b *beegoAppConfig) DefaultStrings(key string, defaultVal []string) []strin
|
|||||||
return defaultVal
|
return defaultVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) DefaultInt(key string, defaultVal int) int {
|
func (b *beegoAppConfig) DefaultInt(key string, defaultVal int) int {
|
||||||
if v, err := b.Int(key); err == nil {
|
if v, err := b.Int(key); err == nil {
|
||||||
return v
|
return v
|
||||||
@ -496,6 +517,7 @@ func (b *beegoAppConfig) DefaultInt(key string, defaultVal int) int {
|
|||||||
return defaultVal
|
return defaultVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) DefaultInt64(key string, defaultVal int64) int64 {
|
func (b *beegoAppConfig) DefaultInt64(key string, defaultVal int64) int64 {
|
||||||
if v, err := b.Int64(key); err == nil {
|
if v, err := b.Int64(key); err == nil {
|
||||||
return v
|
return v
|
||||||
@ -503,6 +525,7 @@ func (b *beegoAppConfig) DefaultInt64(key string, defaultVal int64) int64 {
|
|||||||
return defaultVal
|
return defaultVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) DefaultBool(key string, defaultVal bool) bool {
|
func (b *beegoAppConfig) DefaultBool(key string, defaultVal bool) bool {
|
||||||
if v, err := b.Bool(key); err == nil {
|
if v, err := b.Bool(key); err == nil {
|
||||||
return v
|
return v
|
||||||
@ -510,6 +533,7 @@ func (b *beegoAppConfig) DefaultBool(key string, defaultVal bool) bool {
|
|||||||
return defaultVal
|
return defaultVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) DefaultFloat(key string, defaultVal float64) float64 {
|
func (b *beegoAppConfig) DefaultFloat(key string, defaultVal float64) float64 {
|
||||||
if v, err := b.Float(key); err == nil {
|
if v, err := b.Float(key); err == nil {
|
||||||
return v
|
return v
|
||||||
@ -517,14 +541,17 @@ func (b *beegoAppConfig) DefaultFloat(key string, defaultVal float64) float64 {
|
|||||||
return defaultVal
|
return defaultVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) DIY(key string) (interface{}, error) {
|
func (b *beegoAppConfig) DIY(key string) (interface{}, error) {
|
||||||
return b.innerConfig.DIY(key)
|
return b.innerConfig.DIY(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) GetSection(section string) (map[string]string, error) {
|
func (b *beegoAppConfig) GetSection(section string) (map[string]string, error) {
|
||||||
return b.innerConfig.GetSection(section)
|
return b.innerConfig.GetSection(section)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (b *beegoAppConfig) SaveConfigFile(filename string) error {
|
func (b *beegoAppConfig) SaveConfigFile(filename string) error {
|
||||||
return b.innerConfig.SaveConfigFile(filename)
|
return b.innerConfig.SaveConfigFile(filename)
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,15 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrAbort custom error when user stop request handler manually.
|
// ErrAbort custom error when user stop request handler manually.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
ErrAbort = errors.New("user stop run")
|
ErrAbort = errors.New("user stop run")
|
||||||
// GlobalControllerRouter store comments with controller. pkgpath+controller:comments
|
// GlobalControllerRouter store comments with controller. pkgpath+controller:comments
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
GlobalControllerRouter = make(map[string][]ControllerComments)
|
GlobalControllerRouter = make(map[string][]ControllerComments)
|
||||||
)
|
)
|
||||||
|
|
||||||
// ControllerFilter store the filter for controller
|
// ControllerFilter store the filter for controller
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type ControllerFilter struct {
|
type ControllerFilter struct {
|
||||||
Pattern string
|
Pattern string
|
||||||
Pos int
|
Pos int
|
||||||
@ -50,6 +53,7 @@ type ControllerFilter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ControllerFilterComments store the comment for controller level filter
|
// ControllerFilterComments store the comment for controller level filter
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type ControllerFilterComments struct {
|
type ControllerFilterComments struct {
|
||||||
Pattern string
|
Pattern string
|
||||||
Pos int
|
Pos int
|
||||||
@ -59,12 +63,14 @@ type ControllerFilterComments struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ControllerImportComments store the import comment for controller needed
|
// ControllerImportComments store the import comment for controller needed
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type ControllerImportComments struct {
|
type ControllerImportComments struct {
|
||||||
ImportPath string
|
ImportPath string
|
||||||
ImportAlias string
|
ImportAlias string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ControllerComments store the comment for the controller method
|
// ControllerComments store the comment for the controller method
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type ControllerComments struct {
|
type ControllerComments struct {
|
||||||
Method string
|
Method string
|
||||||
Router string
|
Router string
|
||||||
@ -77,6 +83,7 @@ type ControllerComments struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ControllerCommentsSlice implements the sort interface
|
// ControllerCommentsSlice implements the sort interface
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type ControllerCommentsSlice []ControllerComments
|
type ControllerCommentsSlice []ControllerComments
|
||||||
|
|
||||||
func (p ControllerCommentsSlice) Len() int { return len(p) }
|
func (p ControllerCommentsSlice) Len() int { return len(p) }
|
||||||
@ -85,6 +92,7 @@ func (p ControllerCommentsSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
|||||||
|
|
||||||
// Controller defines some basic http request handler operations, such as
|
// Controller defines some basic http request handler operations, such as
|
||||||
// http context, template and view, session and xsrf.
|
// http context, template and view, session and xsrf.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
// context data
|
// context data
|
||||||
Ctx *context.Context
|
Ctx *context.Context
|
||||||
@ -115,6 +123,7 @@ type Controller struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ControllerInterface is an interface to uniform all controller handler.
|
// ControllerInterface is an interface to uniform all controller handler.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type ControllerInterface interface {
|
type ControllerInterface interface {
|
||||||
Init(ct *context.Context, controllerName, actionName string, app interface{})
|
Init(ct *context.Context, controllerName, actionName string, app interface{})
|
||||||
Prepare()
|
Prepare()
|
||||||
@ -135,6 +144,7 @@ type ControllerInterface interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init generates default values of controller operations.
|
// Init generates default values of controller operations.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
|
func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
|
||||||
c.Layout = ""
|
c.Layout = ""
|
||||||
c.TplName = ""
|
c.TplName = ""
|
||||||
@ -150,42 +160,51 @@ func (c *Controller) Init(ctx *context.Context, controllerName, actionName strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepare runs after Init before request function execution.
|
// Prepare runs after Init before request function execution.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Prepare() {}
|
func (c *Controller) Prepare() {}
|
||||||
|
|
||||||
// Finish runs after request function execution.
|
// Finish runs after request function execution.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Finish() {}
|
func (c *Controller) Finish() {}
|
||||||
|
|
||||||
// Get adds a request function to handle GET request.
|
// Get adds a request function to handle GET request.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Get() {
|
func (c *Controller) Get() {
|
||||||
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post adds a request function to handle POST request.
|
// Post adds a request function to handle POST request.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Post() {
|
func (c *Controller) Post() {
|
||||||
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete adds a request function to handle DELETE request.
|
// Delete adds a request function to handle DELETE request.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Delete() {
|
func (c *Controller) Delete() {
|
||||||
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put adds a request function to handle PUT request.
|
// Put adds a request function to handle PUT request.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Put() {
|
func (c *Controller) Put() {
|
||||||
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Head adds a request function to handle HEAD request.
|
// Head adds a request function to handle HEAD request.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Head() {
|
func (c *Controller) Head() {
|
||||||
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Patch adds a request function to handle PATCH request.
|
// Patch adds a request function to handle PATCH request.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Patch() {
|
func (c *Controller) Patch() {
|
||||||
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options adds a request function to handle OPTIONS request.
|
// Options adds a request function to handle OPTIONS request.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Options() {
|
func (c *Controller) Options() {
|
||||||
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
@ -198,6 +217,7 @@ func (c *Controller) Options() {
|
|||||||
// reflect the message received, excluding some fields described below,
|
// reflect the message received, excluding some fields described below,
|
||||||
// back to the client as the message body of a 200 (OK) response with a
|
// back to the client as the message body of a 200 (OK) response with a
|
||||||
// Content-Type of "message/http" (Section 8.3.1 of [RFC7230]).
|
// Content-Type of "message/http" (Section 8.3.1 of [RFC7230]).
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Trace() {
|
func (c *Controller) Trace() {
|
||||||
ts := func(h http.Header) (hs string) {
|
ts := func(h http.Header) (hs string) {
|
||||||
for k, v := range h {
|
for k, v := range h {
|
||||||
@ -213,6 +233,7 @@ func (c *Controller) Trace() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HandlerFunc call function with the name
|
// HandlerFunc call function with the name
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) HandlerFunc(fnname string) bool {
|
func (c *Controller) HandlerFunc(fnname string) bool {
|
||||||
if v, ok := c.methodMapping[fnname]; ok {
|
if v, ok := c.methodMapping[fnname]; ok {
|
||||||
v()
|
v()
|
||||||
@ -222,14 +243,17 @@ func (c *Controller) HandlerFunc(fnname string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// URLMapping register the internal Controller router.
|
// URLMapping register the internal Controller router.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) URLMapping() {}
|
func (c *Controller) URLMapping() {}
|
||||||
|
|
||||||
// Mapping the method to function
|
// Mapping the method to function
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Mapping(method string, fn func()) {
|
func (c *Controller) Mapping(method string, fn func()) {
|
||||||
c.methodMapping[method] = fn
|
c.methodMapping[method] = fn
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render sends the response with rendered template bytes as text/html type.
|
// Render sends the response with rendered template bytes as text/html type.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Render() error {
|
func (c *Controller) Render() error {
|
||||||
if !c.EnableRender {
|
if !c.EnableRender {
|
||||||
return nil
|
return nil
|
||||||
@ -247,12 +271,14 @@ func (c *Controller) Render() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RenderString returns the rendered template string. Do not send out response.
|
// RenderString returns the rendered template string. Do not send out response.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) RenderString() (string, error) {
|
func (c *Controller) RenderString() (string, error) {
|
||||||
b, e := c.RenderBytes()
|
b, e := c.RenderBytes()
|
||||||
return string(b), e
|
return string(b), e
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderBytes returns the bytes of rendered template string. Do not send out response.
|
// RenderBytes returns the bytes of rendered template string. Do not send out response.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) RenderBytes() ([]byte, error) {
|
func (c *Controller) RenderBytes() ([]byte, error) {
|
||||||
buf, err := c.renderTemplate()
|
buf, err := c.renderTemplate()
|
||||||
//if the controller has set layout, then first get the tplName's content set the content to the layout
|
//if the controller has set layout, then first get the tplName's content set the content to the layout
|
||||||
@ -314,12 +340,14 @@ func (c *Controller) viewPath() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Redirect sends the redirection response to url with status code.
|
// Redirect sends the redirection response to url with status code.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Redirect(url string, code int) {
|
func (c *Controller) Redirect(url string, code int) {
|
||||||
LogAccess(c.Ctx, nil, code)
|
LogAccess(c.Ctx, nil, code)
|
||||||
c.Ctx.Redirect(code, url)
|
c.Ctx.Redirect(code, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetData set the data depending on the accepted
|
// SetData set the data depending on the accepted
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) SetData(data interface{}) {
|
func (c *Controller) SetData(data interface{}) {
|
||||||
accept := c.Ctx.Input.Header("Accept")
|
accept := c.Ctx.Input.Header("Accept")
|
||||||
switch accept {
|
switch accept {
|
||||||
@ -333,6 +361,7 @@ func (c *Controller) SetData(data interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Abort stops controller handler and show the error data if code is defined in ErrorMap or code string.
|
// Abort stops controller handler and show the error data if code is defined in ErrorMap or code string.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Abort(code string) {
|
func (c *Controller) Abort(code string) {
|
||||||
status, err := strconv.Atoi(code)
|
status, err := strconv.Atoi(code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -342,6 +371,7 @@ func (c *Controller) Abort(code string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CustomAbort stops controller handler and show the error data, it's similar Aborts, but support status code and body.
|
// CustomAbort stops controller handler and show the error data, it's similar Aborts, but support status code and body.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) CustomAbort(status int, body string) {
|
func (c *Controller) CustomAbort(status int, body string) {
|
||||||
// first panic from ErrorMaps, it is user defined error functions.
|
// first panic from ErrorMaps, it is user defined error functions.
|
||||||
if _, ok := ErrorMaps[body]; ok {
|
if _, ok := ErrorMaps[body]; ok {
|
||||||
@ -355,12 +385,14 @@ func (c *Controller) CustomAbort(status int, body string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StopRun makes panic of USERSTOPRUN error and go to recover function if defined.
|
// StopRun makes panic of USERSTOPRUN error and go to recover function if defined.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) StopRun() {
|
func (c *Controller) StopRun() {
|
||||||
panic(ErrAbort)
|
panic(ErrAbort)
|
||||||
}
|
}
|
||||||
|
|
||||||
// URLFor does another controller handler in this request function.
|
// URLFor does another controller handler in this request function.
|
||||||
// it goes to this controller method if endpoint is not clear.
|
// it goes to this controller method if endpoint is not clear.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) URLFor(endpoint string, values ...interface{}) string {
|
func (c *Controller) URLFor(endpoint string, values ...interface{}) string {
|
||||||
if len(endpoint) == 0 {
|
if len(endpoint) == 0 {
|
||||||
return ""
|
return ""
|
||||||
@ -372,6 +404,7 @@ func (c *Controller) URLFor(endpoint string, values ...interface{}) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServeJSON sends a json response with encoding charset.
|
// ServeJSON sends a json response with encoding charset.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) ServeJSON(encoding ...bool) {
|
func (c *Controller) ServeJSON(encoding ...bool) {
|
||||||
var (
|
var (
|
||||||
hasIndent = BConfig.RunMode != PROD
|
hasIndent = BConfig.RunMode != PROD
|
||||||
@ -382,23 +415,27 @@ func (c *Controller) ServeJSON(encoding ...bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServeJSONP sends a jsonp response.
|
// ServeJSONP sends a jsonp response.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) ServeJSONP() {
|
func (c *Controller) ServeJSONP() {
|
||||||
hasIndent := BConfig.RunMode != PROD
|
hasIndent := BConfig.RunMode != PROD
|
||||||
c.Ctx.Output.JSONP(c.Data["jsonp"], hasIndent)
|
c.Ctx.Output.JSONP(c.Data["jsonp"], hasIndent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeXML sends xml response.
|
// ServeXML sends xml response.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) ServeXML() {
|
func (c *Controller) ServeXML() {
|
||||||
hasIndent := BConfig.RunMode != PROD
|
hasIndent := BConfig.RunMode != PROD
|
||||||
c.Ctx.Output.XML(c.Data["xml"], hasIndent)
|
c.Ctx.Output.XML(c.Data["xml"], hasIndent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeYAML sends yaml response.
|
// ServeYAML sends yaml response.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) ServeYAML() {
|
func (c *Controller) ServeYAML() {
|
||||||
c.Ctx.Output.YAML(c.Data["yaml"])
|
c.Ctx.Output.YAML(c.Data["yaml"])
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeFormatted serve YAML, XML OR JSON, depending on the value of the Accept header
|
// ServeFormatted serve YAML, XML OR JSON, depending on the value of the Accept header
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) ServeFormatted(encoding ...bool) {
|
func (c *Controller) ServeFormatted(encoding ...bool) {
|
||||||
hasIndent := BConfig.RunMode != PROD
|
hasIndent := BConfig.RunMode != PROD
|
||||||
hasEncoding := len(encoding) > 0 && encoding[0]
|
hasEncoding := len(encoding) > 0 && encoding[0]
|
||||||
@ -406,6 +443,7 @@ func (c *Controller) ServeFormatted(encoding ...bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Input returns the input data map from POST or PUT request body and query string.
|
// Input returns the input data map from POST or PUT request body and query string.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) Input() url.Values {
|
func (c *Controller) Input() url.Values {
|
||||||
if c.Ctx.Request.Form == nil {
|
if c.Ctx.Request.Form == nil {
|
||||||
c.Ctx.Request.ParseForm()
|
c.Ctx.Request.ParseForm()
|
||||||
@ -414,11 +452,13 @@ func (c *Controller) Input() url.Values {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParseForm maps input data map to obj struct.
|
// ParseForm maps input data map to obj struct.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) ParseForm(obj interface{}) error {
|
func (c *Controller) ParseForm(obj interface{}) error {
|
||||||
return ParseForm(c.Input(), obj)
|
return ParseForm(c.Input(), obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetString returns the input value by key string or the default value while it's present and input is blank
|
// GetString returns the input value by key string or the default value while it's present and input is blank
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetString(key string, def ...string) string {
|
func (c *Controller) GetString(key string, def ...string) string {
|
||||||
if v := c.Ctx.Input.Query(key); v != "" {
|
if v := c.Ctx.Input.Query(key); v != "" {
|
||||||
return v
|
return v
|
||||||
@ -431,6 +471,7 @@ func (c *Controller) GetString(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
|
// 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.
|
// it's designed for multi-value input field such as checkbox(input[type=checkbox]), multi-selection.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetStrings(key string, def ...[]string) []string {
|
func (c *Controller) GetStrings(key string, def ...[]string) []string {
|
||||||
var defv []string
|
var defv []string
|
||||||
if len(def) > 0 {
|
if len(def) > 0 {
|
||||||
@ -447,6 +488,7 @@ func (c *Controller) GetStrings(key string, def ...[]string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetInt returns input as an int or the default value while it's present and input is blank
|
// GetInt returns input as an int or the default value while it's present and input is blank
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetInt(key string, def ...int) (int, error) {
|
func (c *Controller) GetInt(key string, def ...int) (int, error) {
|
||||||
strv := c.Ctx.Input.Query(key)
|
strv := c.Ctx.Input.Query(key)
|
||||||
if len(strv) == 0 && len(def) > 0 {
|
if len(strv) == 0 && len(def) > 0 {
|
||||||
@ -456,6 +498,7 @@ func (c *Controller) GetInt(key string, def ...int) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetInt8 return input as an int8 or the default value while it's present and input is blank
|
// GetInt8 return input as an int8 or the default value while it's present and input is blank
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetInt8(key string, def ...int8) (int8, error) {
|
func (c *Controller) GetInt8(key string, def ...int8) (int8, error) {
|
||||||
strv := c.Ctx.Input.Query(key)
|
strv := c.Ctx.Input.Query(key)
|
||||||
if len(strv) == 0 && len(def) > 0 {
|
if len(strv) == 0 && len(def) > 0 {
|
||||||
@ -466,6 +509,7 @@ func (c *Controller) GetInt8(key string, def ...int8) (int8, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUint8 return input as an uint8 or the default value while it's present and input is blank
|
// GetUint8 return input as an uint8 or the default value while it's present and input is blank
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetUint8(key string, def ...uint8) (uint8, error) {
|
func (c *Controller) GetUint8(key string, def ...uint8) (uint8, error) {
|
||||||
strv := c.Ctx.Input.Query(key)
|
strv := c.Ctx.Input.Query(key)
|
||||||
if len(strv) == 0 && len(def) > 0 {
|
if len(strv) == 0 && len(def) > 0 {
|
||||||
@ -476,6 +520,7 @@ func (c *Controller) GetUint8(key string, def ...uint8) (uint8, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetInt16 returns input as an int16 or the default value while it's present and input is blank
|
// GetInt16 returns input as an int16 or the default value while it's present and input is blank
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetInt16(key string, def ...int16) (int16, error) {
|
func (c *Controller) GetInt16(key string, def ...int16) (int16, error) {
|
||||||
strv := c.Ctx.Input.Query(key)
|
strv := c.Ctx.Input.Query(key)
|
||||||
if len(strv) == 0 && len(def) > 0 {
|
if len(strv) == 0 && len(def) > 0 {
|
||||||
@ -486,6 +531,7 @@ func (c *Controller) GetInt16(key string, def ...int16) (int16, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUint16 returns input as an uint16 or the default value while it's present and input is blank
|
// GetUint16 returns input as an uint16 or the default value while it's present and input is blank
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetUint16(key string, def ...uint16) (uint16, error) {
|
func (c *Controller) GetUint16(key string, def ...uint16) (uint16, error) {
|
||||||
strv := c.Ctx.Input.Query(key)
|
strv := c.Ctx.Input.Query(key)
|
||||||
if len(strv) == 0 && len(def) > 0 {
|
if len(strv) == 0 && len(def) > 0 {
|
||||||
@ -496,6 +542,7 @@ func (c *Controller) GetUint16(key string, def ...uint16) (uint16, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetInt32 returns input as an int32 or the default value while it's present and input is blank
|
// GetInt32 returns input as an int32 or the default value while it's present and input is blank
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetInt32(key string, def ...int32) (int32, error) {
|
func (c *Controller) GetInt32(key string, def ...int32) (int32, error) {
|
||||||
strv := c.Ctx.Input.Query(key)
|
strv := c.Ctx.Input.Query(key)
|
||||||
if len(strv) == 0 && len(def) > 0 {
|
if len(strv) == 0 && len(def) > 0 {
|
||||||
@ -506,6 +553,7 @@ func (c *Controller) GetInt32(key string, def ...int32) (int32, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUint32 returns input as an uint32 or the default value while it's present and input is blank
|
// GetUint32 returns input as an uint32 or the default value while it's present and input is blank
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetUint32(key string, def ...uint32) (uint32, error) {
|
func (c *Controller) GetUint32(key string, def ...uint32) (uint32, error) {
|
||||||
strv := c.Ctx.Input.Query(key)
|
strv := c.Ctx.Input.Query(key)
|
||||||
if len(strv) == 0 && len(def) > 0 {
|
if len(strv) == 0 && len(def) > 0 {
|
||||||
@ -516,6 +564,7 @@ func (c *Controller) GetUint32(key string, def ...uint32) (uint32, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetInt64 returns input value as int64 or the default value while it's present and input is blank.
|
// GetInt64 returns input value as int64 or the default value while it's present and input is blank.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetInt64(key string, def ...int64) (int64, error) {
|
func (c *Controller) GetInt64(key string, def ...int64) (int64, error) {
|
||||||
strv := c.Ctx.Input.Query(key)
|
strv := c.Ctx.Input.Query(key)
|
||||||
if len(strv) == 0 && len(def) > 0 {
|
if len(strv) == 0 && len(def) > 0 {
|
||||||
@ -525,6 +574,7 @@ func (c *Controller) GetInt64(key string, def ...int64) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUint64 returns input value as uint64 or the default value while it's present and input is blank.
|
// GetUint64 returns input value as uint64 or the default value while it's present and input is blank.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetUint64(key string, def ...uint64) (uint64, error) {
|
func (c *Controller) GetUint64(key string, def ...uint64) (uint64, error) {
|
||||||
strv := c.Ctx.Input.Query(key)
|
strv := c.Ctx.Input.Query(key)
|
||||||
if len(strv) == 0 && len(def) > 0 {
|
if len(strv) == 0 && len(def) > 0 {
|
||||||
@ -534,6 +584,7 @@ func (c *Controller) GetUint64(key string, def ...uint64) (uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetBool returns input value as bool or the default value while it's present and input is blank.
|
// GetBool returns input value as bool or the default value while it's present and input is blank.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetBool(key string, def ...bool) (bool, error) {
|
func (c *Controller) GetBool(key string, def ...bool) (bool, error) {
|
||||||
strv := c.Ctx.Input.Query(key)
|
strv := c.Ctx.Input.Query(key)
|
||||||
if len(strv) == 0 && len(def) > 0 {
|
if len(strv) == 0 && len(def) > 0 {
|
||||||
@ -543,6 +594,7 @@ func (c *Controller) GetBool(key string, def ...bool) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetFloat returns input value as float64 or the default value while it's present and input is blank.
|
// GetFloat returns input value as float64 or the default value while it's present and input is blank.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetFloat(key string, def ...float64) (float64, error) {
|
func (c *Controller) GetFloat(key string, def ...float64) (float64, error) {
|
||||||
strv := c.Ctx.Input.Query(key)
|
strv := c.Ctx.Input.Query(key)
|
||||||
if len(strv) == 0 && len(def) > 0 {
|
if len(strv) == 0 && len(def) > 0 {
|
||||||
@ -553,6 +605,7 @@ func (c *Controller) GetFloat(key string, def ...float64) (float64, error) {
|
|||||||
|
|
||||||
// GetFile returns the file data in file upload field named as key.
|
// GetFile returns the file data in file upload field named as key.
|
||||||
// it returns the first one of multi-uploaded files.
|
// it returns the first one of multi-uploaded files.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader, error) {
|
func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader, error) {
|
||||||
return c.Ctx.Request.FormFile(key)
|
return c.Ctx.Request.FormFile(key)
|
||||||
}
|
}
|
||||||
@ -584,6 +637,7 @@ func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader,
|
|||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetFiles(key string) ([]*multipart.FileHeader, error) {
|
func (c *Controller) GetFiles(key string) ([]*multipart.FileHeader, error) {
|
||||||
if files, ok := c.Ctx.Request.MultipartForm.File[key]; ok {
|
if files, ok := c.Ctx.Request.MultipartForm.File[key]; ok {
|
||||||
return files, nil
|
return files, nil
|
||||||
@ -593,6 +647,7 @@ func (c *Controller) GetFiles(key string) ([]*multipart.FileHeader, error) {
|
|||||||
|
|
||||||
// SaveToFile saves uploaded file to new path.
|
// SaveToFile saves uploaded file to new path.
|
||||||
// it only operates the first one of mutil-upload form file field.
|
// it only operates the first one of mutil-upload form file field.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) SaveToFile(fromfile, tofile string) error {
|
func (c *Controller) SaveToFile(fromfile, tofile string) error {
|
||||||
file, _, err := c.Ctx.Request.FormFile(fromfile)
|
file, _, err := c.Ctx.Request.FormFile(fromfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -609,6 +664,7 @@ func (c *Controller) SaveToFile(fromfile, tofile string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StartSession starts session and load old session data info this controller.
|
// StartSession starts session and load old session data info this controller.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) StartSession() session.Store {
|
func (c *Controller) StartSession() session.Store {
|
||||||
if c.CruSession == nil {
|
if c.CruSession == nil {
|
||||||
c.CruSession = c.Ctx.Input.CruSession
|
c.CruSession = c.Ctx.Input.CruSession
|
||||||
@ -617,6 +673,7 @@ func (c *Controller) StartSession() session.Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetSession puts value into session.
|
// SetSession puts value into session.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) SetSession(name interface{}, value interface{}) {
|
func (c *Controller) SetSession(name interface{}, value interface{}) {
|
||||||
if c.CruSession == nil {
|
if c.CruSession == nil {
|
||||||
c.StartSession()
|
c.StartSession()
|
||||||
@ -625,6 +682,7 @@ func (c *Controller) SetSession(name interface{}, value interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSession gets value from session.
|
// GetSession gets value from session.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetSession(name interface{}) interface{} {
|
func (c *Controller) GetSession(name interface{}) interface{} {
|
||||||
if c.CruSession == nil {
|
if c.CruSession == nil {
|
||||||
c.StartSession()
|
c.StartSession()
|
||||||
@ -633,6 +691,7 @@ func (c *Controller) GetSession(name interface{}) interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DelSession removes value from session.
|
// DelSession removes value from session.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) DelSession(name interface{}) {
|
func (c *Controller) DelSession(name interface{}) {
|
||||||
if c.CruSession == nil {
|
if c.CruSession == nil {
|
||||||
c.StartSession()
|
c.StartSession()
|
||||||
@ -642,6 +701,7 @@ func (c *Controller) DelSession(name interface{}) {
|
|||||||
|
|
||||||
// SessionRegenerateID regenerates session id for this session.
|
// SessionRegenerateID regenerates session id for this session.
|
||||||
// the session data have no changes.
|
// the session data have no changes.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) SessionRegenerateID() {
|
func (c *Controller) SessionRegenerateID() {
|
||||||
if c.CruSession != nil {
|
if c.CruSession != nil {
|
||||||
c.CruSession.SessionRelease(c.Ctx.ResponseWriter)
|
c.CruSession.SessionRelease(c.Ctx.ResponseWriter)
|
||||||
@ -651,6 +711,7 @@ func (c *Controller) SessionRegenerateID() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DestroySession cleans session data and session cookie.
|
// DestroySession cleans session data and session cookie.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) DestroySession() {
|
func (c *Controller) DestroySession() {
|
||||||
c.Ctx.Input.CruSession.Flush()
|
c.Ctx.Input.CruSession.Flush()
|
||||||
c.Ctx.Input.CruSession = nil
|
c.Ctx.Input.CruSession = nil
|
||||||
@ -658,21 +719,25 @@ func (c *Controller) DestroySession() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsAjax returns this request is ajax or not.
|
// IsAjax returns this request is ajax or not.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) IsAjax() bool {
|
func (c *Controller) IsAjax() bool {
|
||||||
return c.Ctx.Input.IsAjax()
|
return c.Ctx.Input.IsAjax()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSecureCookie returns decoded cookie value from encoded browser cookie values.
|
// GetSecureCookie returns decoded cookie value from encoded browser cookie values.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetSecureCookie(Secret, key string) (string, bool) {
|
func (c *Controller) GetSecureCookie(Secret, key string) (string, bool) {
|
||||||
return c.Ctx.GetSecureCookie(Secret, key)
|
return c.Ctx.GetSecureCookie(Secret, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSecureCookie puts value into cookie after encoded the value.
|
// SetSecureCookie puts value into cookie after encoded the value.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) SetSecureCookie(Secret, name, value string, others ...interface{}) {
|
func (c *Controller) SetSecureCookie(Secret, name, value string, others ...interface{}) {
|
||||||
c.Ctx.SetSecureCookie(Secret, name, value, others...)
|
c.Ctx.SetSecureCookie(Secret, name, value, others...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// XSRFToken creates a CSRF token string and returns.
|
// XSRFToken creates a CSRF token string and returns.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) XSRFToken() string {
|
func (c *Controller) XSRFToken() string {
|
||||||
if c._xsrfToken == "" {
|
if c._xsrfToken == "" {
|
||||||
expire := int64(BConfig.WebConfig.XSRFExpire)
|
expire := int64(BConfig.WebConfig.XSRFExpire)
|
||||||
@ -687,6 +752,7 @@ func (c *Controller) XSRFToken() string {
|
|||||||
// CheckXSRFCookie checks xsrf token in this request is valid or not.
|
// CheckXSRFCookie checks xsrf token in this request is valid or not.
|
||||||
// the token can provided in request header "X-Xsrftoken" and "X-CsrfToken"
|
// the token can provided in request header "X-Xsrftoken" and "X-CsrfToken"
|
||||||
// or in form field value named as "_xsrf".
|
// or in form field value named as "_xsrf".
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) CheckXSRFCookie() bool {
|
func (c *Controller) CheckXSRFCookie() bool {
|
||||||
if !c.EnableXSRF {
|
if !c.EnableXSRF {
|
||||||
return true
|
return true
|
||||||
@ -695,12 +761,14 @@ func (c *Controller) CheckXSRFCookie() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XSRFFormHTML writes an input field contains xsrf token value.
|
// XSRFFormHTML writes an input field contains xsrf token value.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) XSRFFormHTML() string {
|
func (c *Controller) XSRFFormHTML() string {
|
||||||
return `<input type="hidden" name="_xsrf" value="` +
|
return `<input type="hidden" name="_xsrf" value="` +
|
||||||
c.XSRFToken() + `" />`
|
c.XSRFToken() + `" />`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetControllerAndAction gets the executing controller name and action name.
|
// GetControllerAndAction gets the executing controller name and action name.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *Controller) GetControllerAndAction() (string, string) {
|
func (c *Controller) GetControllerAndAction() (string, string) {
|
||||||
return c.controllerName, c.actionName
|
return c.controllerName, c.actionName
|
||||||
}
|
}
|
||||||
|
2
doc.go
2
doc.go
@ -13,5 +13,7 @@ beego is inspired by Tornado, Sinatra and Flask with the added benefit of some G
|
|||||||
}
|
}
|
||||||
|
|
||||||
more information: http://beego.me
|
more information: http://beego.me
|
||||||
|
|
||||||
|
Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
*/
|
*/
|
||||||
package beego
|
package beego
|
||||||
|
4
error.go
4
error.go
@ -205,6 +205,7 @@ type errorInfo struct {
|
|||||||
|
|
||||||
// ErrorMaps holds map of http handlers for each error string.
|
// ErrorMaps holds map of http handlers for each error string.
|
||||||
// there is 10 kinds default error(40x and 50x)
|
// there is 10 kinds default error(40x and 50x)
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
var ErrorMaps = make(map[string]*errorInfo, 10)
|
var ErrorMaps = make(map[string]*errorInfo, 10)
|
||||||
|
|
||||||
// show 401 unauthorized error.
|
// show 401 unauthorized error.
|
||||||
@ -387,6 +388,7 @@ func responseError(rw http.ResponseWriter, r *http.Request, errCode int, errCont
|
|||||||
// usage:
|
// usage:
|
||||||
// beego.ErrorHandler("404",NotFound)
|
// beego.ErrorHandler("404",NotFound)
|
||||||
// beego.ErrorHandler("500",InternalServerError)
|
// beego.ErrorHandler("500",InternalServerError)
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func ErrorHandler(code string, h http.HandlerFunc) *App {
|
func ErrorHandler(code string, h http.HandlerFunc) *App {
|
||||||
ErrorMaps[code] = &errorInfo{
|
ErrorMaps[code] = &errorInfo{
|
||||||
errorType: errorTypeHandler,
|
errorType: errorTypeHandler,
|
||||||
@ -399,6 +401,7 @@ func ErrorHandler(code string, h http.HandlerFunc) *App {
|
|||||||
// ErrorController registers ControllerInterface to each http err code string.
|
// ErrorController registers ControllerInterface to each http err code string.
|
||||||
// usage:
|
// usage:
|
||||||
// beego.ErrorController(&controllers.ErrorController{})
|
// beego.ErrorController(&controllers.ErrorController{})
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func ErrorController(c ControllerInterface) *App {
|
func ErrorController(c ControllerInterface) *App {
|
||||||
reflectVal := reflect.ValueOf(c)
|
reflectVal := reflect.ValueOf(c)
|
||||||
rt := reflectVal.Type()
|
rt := reflectVal.Type()
|
||||||
@ -418,6 +421,7 @@ func ErrorController(c ControllerInterface) *App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Exception Write HttpStatus with errCode and Exec error handler if exist.
|
// Exception Write HttpStatus with errCode and Exec error handler if exist.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Exception(errCode uint64, ctx *context.Context) {
|
func Exception(errCode uint64, ctx *context.Context) {
|
||||||
exception(strconv.FormatUint(errCode, 10), ctx)
|
exception(strconv.FormatUint(errCode, 10), ctx)
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,13 @@ package beego
|
|||||||
import "github.com/astaxie/beego/context"
|
import "github.com/astaxie/beego/context"
|
||||||
|
|
||||||
// FilterFunc defines a filter function which is invoked before the controller handler is executed.
|
// FilterFunc defines a filter function which is invoked before the controller handler is executed.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type FilterFunc func(*context.Context)
|
type FilterFunc func(*context.Context)
|
||||||
|
|
||||||
// FilterRouter defines a filter operation which is invoked before the controller handler is executed.
|
// FilterRouter defines a filter operation which is invoked before the controller handler is executed.
|
||||||
// It can match the URL against a pattern, and execute a filter function
|
// It can match the URL against a pattern, and execute a filter function
|
||||||
// when a request with a matching URL arrives.
|
// when a request with a matching URL arrives.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type FilterRouter struct {
|
type FilterRouter struct {
|
||||||
filterFunc FilterFunc
|
filterFunc FilterFunc
|
||||||
tree *Tree
|
tree *Tree
|
||||||
@ -33,6 +35,7 @@ type FilterRouter struct {
|
|||||||
// ValidRouter checks if the current request is matched by this filter.
|
// ValidRouter checks if the current request is matched by this filter.
|
||||||
// If the request is matched, the values of the URL parameters defined
|
// If the request is matched, the values of the URL parameters defined
|
||||||
// by the filter pattern are also returned.
|
// by the filter pattern are also returned.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (f *FilterRouter) ValidRouter(url string, ctx *context.Context) bool {
|
func (f *FilterRouter) ValidRouter(url string, ctx *context.Context) bool {
|
||||||
isOk := f.tree.Match(url, ctx)
|
isOk := f.tree.Match(url, ctx)
|
||||||
if isOk != nil {
|
if isOk != nil {
|
||||||
|
9
flash.go
9
flash.go
@ -21,11 +21,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// FlashData is a tools to maintain data when using across request.
|
// FlashData is a tools to maintain data when using across request.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type FlashData struct {
|
type FlashData struct {
|
||||||
Data map[string]string
|
Data map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFlash return a new empty FlashData struct.
|
// NewFlash return a new empty FlashData struct.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NewFlash() *FlashData {
|
func NewFlash() *FlashData {
|
||||||
return &FlashData{
|
return &FlashData{
|
||||||
Data: make(map[string]string),
|
Data: make(map[string]string),
|
||||||
@ -33,6 +35,7 @@ func NewFlash() *FlashData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set message to flash
|
// Set message to flash
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (fd *FlashData) Set(key string, msg string, args ...interface{}) {
|
func (fd *FlashData) Set(key string, msg string, args ...interface{}) {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
fd.Data[key] = msg
|
fd.Data[key] = msg
|
||||||
@ -42,6 +45,7 @@ func (fd *FlashData) Set(key string, msg string, args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Success writes success message to flash.
|
// Success writes success message to flash.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (fd *FlashData) Success(msg string, args ...interface{}) {
|
func (fd *FlashData) Success(msg string, args ...interface{}) {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
fd.Data["success"] = msg
|
fd.Data["success"] = msg
|
||||||
@ -51,6 +55,7 @@ func (fd *FlashData) Success(msg string, args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Notice writes notice message to flash.
|
// Notice writes notice message to flash.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (fd *FlashData) Notice(msg string, args ...interface{}) {
|
func (fd *FlashData) Notice(msg string, args ...interface{}) {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
fd.Data["notice"] = msg
|
fd.Data["notice"] = msg
|
||||||
@ -60,6 +65,7 @@ func (fd *FlashData) Notice(msg string, args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Warning writes warning message to flash.
|
// Warning writes warning message to flash.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (fd *FlashData) Warning(msg string, args ...interface{}) {
|
func (fd *FlashData) Warning(msg string, args ...interface{}) {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
fd.Data["warning"] = msg
|
fd.Data["warning"] = msg
|
||||||
@ -69,6 +75,7 @@ func (fd *FlashData) Warning(msg string, args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Error writes error message to flash.
|
// Error writes error message to flash.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (fd *FlashData) Error(msg string, args ...interface{}) {
|
func (fd *FlashData) Error(msg string, args ...interface{}) {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
fd.Data["error"] = msg
|
fd.Data["error"] = msg
|
||||||
@ -79,6 +86,7 @@ func (fd *FlashData) Error(msg string, args ...interface{}) {
|
|||||||
|
|
||||||
// Store does the saving operation of flash data.
|
// Store does the saving operation of flash data.
|
||||||
// the data are encoded and saved in cookie.
|
// the data are encoded and saved in cookie.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (fd *FlashData) Store(c *Controller) {
|
func (fd *FlashData) Store(c *Controller) {
|
||||||
c.Data["flash"] = fd.Data
|
c.Data["flash"] = fd.Data
|
||||||
var flashValue string
|
var flashValue string
|
||||||
@ -89,6 +97,7 @@ func (fd *FlashData) Store(c *Controller) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReadFromRequest parsed flash data from encoded values in cookie.
|
// ReadFromRequest parsed flash data from encoded values in cookie.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func ReadFromRequest(c *Controller) *FlashData {
|
func ReadFromRequest(c *Controller) *FlashData {
|
||||||
flash := NewFlash()
|
flash := NewFlash()
|
||||||
if cookie, err := c.Ctx.Request.Cookie(BConfig.WebConfig.FlashName); err == nil {
|
if cookie, err := c.Ctx.Request.Cookie(BConfig.WebConfig.FlashName); err == nil {
|
||||||
|
3
fs.go
3
fs.go
@ -6,9 +6,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type FileSystem struct {
|
type FileSystem struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (d FileSystem) Open(name string) (http.File, error) {
|
func (d FileSystem) Open(name string) (http.File, error) {
|
||||||
return os.Open(name)
|
return os.Open(name)
|
||||||
}
|
}
|
||||||
@ -16,6 +18,7 @@ func (d FileSystem) Open(name string) (http.File, error) {
|
|||||||
// Walk walks the file tree rooted at root in filesystem, calling walkFn for each file or
|
// Walk walks the file tree rooted at root in filesystem, calling walkFn for each file or
|
||||||
// directory in the tree, including root. All errors that arise visiting files
|
// directory in the tree, including root. All errors that arise visiting files
|
||||||
// and directories are filtered by walkFn.
|
// and directories are filtered by walkFn.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Walk(fs http.FileSystem, root string, walkFn filepath.WalkFunc) error {
|
func Walk(fs http.FileSystem, root string, walkFn filepath.WalkFunc) error {
|
||||||
|
|
||||||
f, err := fs.Open(root)
|
f, err := fs.Open(root)
|
||||||
|
37
namespace.go
37
namespace.go
@ -24,15 +24,18 @@ import (
|
|||||||
type namespaceCond func(*beecontext.Context) bool
|
type namespaceCond func(*beecontext.Context) bool
|
||||||
|
|
||||||
// LinkNamespace used as link action
|
// LinkNamespace used as link action
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type LinkNamespace func(*Namespace)
|
type LinkNamespace func(*Namespace)
|
||||||
|
|
||||||
// Namespace is store all the info
|
// Namespace is store all the info
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type Namespace struct {
|
type Namespace struct {
|
||||||
prefix string
|
prefix string
|
||||||
handlers *ControllerRegister
|
handlers *ControllerRegister
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNamespace get new Namespace
|
// NewNamespace get new Namespace
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NewNamespace(prefix string, params ...LinkNamespace) *Namespace {
|
func NewNamespace(prefix string, params ...LinkNamespace) *Namespace {
|
||||||
ns := &Namespace{
|
ns := &Namespace{
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
@ -54,6 +57,7 @@ func NewNamespace(prefix string, params ...LinkNamespace) *Namespace {
|
|||||||
// return false
|
// return false
|
||||||
// })
|
// })
|
||||||
// Cond as the first filter
|
// Cond as the first filter
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Cond(cond namespaceCond) *Namespace {
|
func (n *Namespace) Cond(cond namespaceCond) *Namespace {
|
||||||
fn := func(ctx *beecontext.Context) {
|
fn := func(ctx *beecontext.Context) {
|
||||||
if !cond(ctx) {
|
if !cond(ctx) {
|
||||||
@ -83,6 +87,7 @@ func (n *Namespace) Cond(cond namespaceCond) *Namespace {
|
|||||||
// ctx.Redirect(302, "/login")
|
// ctx.Redirect(302, "/login")
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Filter(action string, filter ...FilterFunc) *Namespace {
|
func (n *Namespace) Filter(action string, filter ...FilterFunc) *Namespace {
|
||||||
var a int
|
var a int
|
||||||
if action == "before" {
|
if action == "before" {
|
||||||
@ -98,6 +103,7 @@ func (n *Namespace) Filter(action string, filter ...FilterFunc) *Namespace {
|
|||||||
|
|
||||||
// Router same as beego.Rourer
|
// Router same as beego.Rourer
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#Router
|
// refer: https://godoc.org/github.com/astaxie/beego#Router
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Router(rootpath string, c ControllerInterface, mappingMethods ...string) *Namespace {
|
func (n *Namespace) Router(rootpath string, c ControllerInterface, mappingMethods ...string) *Namespace {
|
||||||
n.handlers.Add(rootpath, c, mappingMethods...)
|
n.handlers.Add(rootpath, c, mappingMethods...)
|
||||||
return n
|
return n
|
||||||
@ -105,6 +111,7 @@ func (n *Namespace) Router(rootpath string, c ControllerInterface, mappingMethod
|
|||||||
|
|
||||||
// AutoRouter same as beego.AutoRouter
|
// AutoRouter same as beego.AutoRouter
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#AutoRouter
|
// refer: https://godoc.org/github.com/astaxie/beego#AutoRouter
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) AutoRouter(c ControllerInterface) *Namespace {
|
func (n *Namespace) AutoRouter(c ControllerInterface) *Namespace {
|
||||||
n.handlers.AddAuto(c)
|
n.handlers.AddAuto(c)
|
||||||
return n
|
return n
|
||||||
@ -112,6 +119,7 @@ func (n *Namespace) AutoRouter(c ControllerInterface) *Namespace {
|
|||||||
|
|
||||||
// AutoPrefix same as beego.AutoPrefix
|
// AutoPrefix same as beego.AutoPrefix
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#AutoPrefix
|
// refer: https://godoc.org/github.com/astaxie/beego#AutoPrefix
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) AutoPrefix(prefix string, c ControllerInterface) *Namespace {
|
func (n *Namespace) AutoPrefix(prefix string, c ControllerInterface) *Namespace {
|
||||||
n.handlers.AddAutoPrefix(prefix, c)
|
n.handlers.AddAutoPrefix(prefix, c)
|
||||||
return n
|
return n
|
||||||
@ -119,6 +127,7 @@ func (n *Namespace) AutoPrefix(prefix string, c ControllerInterface) *Namespace
|
|||||||
|
|
||||||
// Get same as beego.Get
|
// Get same as beego.Get
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#Get
|
// refer: https://godoc.org/github.com/astaxie/beego#Get
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Get(rootpath string, f FilterFunc) *Namespace {
|
func (n *Namespace) Get(rootpath string, f FilterFunc) *Namespace {
|
||||||
n.handlers.Get(rootpath, f)
|
n.handlers.Get(rootpath, f)
|
||||||
return n
|
return n
|
||||||
@ -126,6 +135,7 @@ func (n *Namespace) Get(rootpath string, f FilterFunc) *Namespace {
|
|||||||
|
|
||||||
// Post same as beego.Post
|
// Post same as beego.Post
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#Post
|
// refer: https://godoc.org/github.com/astaxie/beego#Post
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Post(rootpath string, f FilterFunc) *Namespace {
|
func (n *Namespace) Post(rootpath string, f FilterFunc) *Namespace {
|
||||||
n.handlers.Post(rootpath, f)
|
n.handlers.Post(rootpath, f)
|
||||||
return n
|
return n
|
||||||
@ -133,6 +143,7 @@ func (n *Namespace) Post(rootpath string, f FilterFunc) *Namespace {
|
|||||||
|
|
||||||
// Delete same as beego.Delete
|
// Delete same as beego.Delete
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#Delete
|
// refer: https://godoc.org/github.com/astaxie/beego#Delete
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Delete(rootpath string, f FilterFunc) *Namespace {
|
func (n *Namespace) Delete(rootpath string, f FilterFunc) *Namespace {
|
||||||
n.handlers.Delete(rootpath, f)
|
n.handlers.Delete(rootpath, f)
|
||||||
return n
|
return n
|
||||||
@ -140,6 +151,7 @@ func (n *Namespace) Delete(rootpath string, f FilterFunc) *Namespace {
|
|||||||
|
|
||||||
// Put same as beego.Put
|
// Put same as beego.Put
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#Put
|
// refer: https://godoc.org/github.com/astaxie/beego#Put
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Put(rootpath string, f FilterFunc) *Namespace {
|
func (n *Namespace) Put(rootpath string, f FilterFunc) *Namespace {
|
||||||
n.handlers.Put(rootpath, f)
|
n.handlers.Put(rootpath, f)
|
||||||
return n
|
return n
|
||||||
@ -147,6 +159,7 @@ func (n *Namespace) Put(rootpath string, f FilterFunc) *Namespace {
|
|||||||
|
|
||||||
// Head same as beego.Head
|
// Head same as beego.Head
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#Head
|
// refer: https://godoc.org/github.com/astaxie/beego#Head
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Head(rootpath string, f FilterFunc) *Namespace {
|
func (n *Namespace) Head(rootpath string, f FilterFunc) *Namespace {
|
||||||
n.handlers.Head(rootpath, f)
|
n.handlers.Head(rootpath, f)
|
||||||
return n
|
return n
|
||||||
@ -154,6 +167,7 @@ func (n *Namespace) Head(rootpath string, f FilterFunc) *Namespace {
|
|||||||
|
|
||||||
// Options same as beego.Options
|
// Options same as beego.Options
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#Options
|
// refer: https://godoc.org/github.com/astaxie/beego#Options
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Options(rootpath string, f FilterFunc) *Namespace {
|
func (n *Namespace) Options(rootpath string, f FilterFunc) *Namespace {
|
||||||
n.handlers.Options(rootpath, f)
|
n.handlers.Options(rootpath, f)
|
||||||
return n
|
return n
|
||||||
@ -161,6 +175,7 @@ func (n *Namespace) Options(rootpath string, f FilterFunc) *Namespace {
|
|||||||
|
|
||||||
// Patch same as beego.Patch
|
// Patch same as beego.Patch
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#Patch
|
// refer: https://godoc.org/github.com/astaxie/beego#Patch
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Patch(rootpath string, f FilterFunc) *Namespace {
|
func (n *Namespace) Patch(rootpath string, f FilterFunc) *Namespace {
|
||||||
n.handlers.Patch(rootpath, f)
|
n.handlers.Patch(rootpath, f)
|
||||||
return n
|
return n
|
||||||
@ -168,6 +183,7 @@ func (n *Namespace) Patch(rootpath string, f FilterFunc) *Namespace {
|
|||||||
|
|
||||||
// Any same as beego.Any
|
// Any same as beego.Any
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#Any
|
// refer: https://godoc.org/github.com/astaxie/beego#Any
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Any(rootpath string, f FilterFunc) *Namespace {
|
func (n *Namespace) Any(rootpath string, f FilterFunc) *Namespace {
|
||||||
n.handlers.Any(rootpath, f)
|
n.handlers.Any(rootpath, f)
|
||||||
return n
|
return n
|
||||||
@ -175,6 +191,7 @@ func (n *Namespace) Any(rootpath string, f FilterFunc) *Namespace {
|
|||||||
|
|
||||||
// Handler same as beego.Handler
|
// Handler same as beego.Handler
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#Handler
|
// refer: https://godoc.org/github.com/astaxie/beego#Handler
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Handler(rootpath string, h http.Handler) *Namespace {
|
func (n *Namespace) Handler(rootpath string, h http.Handler) *Namespace {
|
||||||
n.handlers.Handler(rootpath, h)
|
n.handlers.Handler(rootpath, h)
|
||||||
return n
|
return n
|
||||||
@ -182,6 +199,7 @@ func (n *Namespace) Handler(rootpath string, h http.Handler) *Namespace {
|
|||||||
|
|
||||||
// Include add include class
|
// Include add include class
|
||||||
// refer: https://godoc.org/github.com/astaxie/beego#Include
|
// refer: https://godoc.org/github.com/astaxie/beego#Include
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Include(cList ...ControllerInterface) *Namespace {
|
func (n *Namespace) Include(cList ...ControllerInterface) *Namespace {
|
||||||
n.handlers.Include(cList...)
|
n.handlers.Include(cList...)
|
||||||
return n
|
return n
|
||||||
@ -204,6 +222,7 @@ func (n *Namespace) Include(cList ...ControllerInterface) *Namespace {
|
|||||||
// ctx.Output.Body([]byte("crminfo"))
|
// ctx.Output.Body([]byte("crminfo"))
|
||||||
// }),
|
// }),
|
||||||
//)
|
//)
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (n *Namespace) Namespace(ns ...*Namespace) *Namespace {
|
func (n *Namespace) Namespace(ns ...*Namespace) *Namespace {
|
||||||
for _, ni := range ns {
|
for _, ni := range ns {
|
||||||
for k, v := range ni.handlers.routers {
|
for k, v := range ni.handlers.routers {
|
||||||
@ -233,6 +252,7 @@ func (n *Namespace) Namespace(ns ...*Namespace) *Namespace {
|
|||||||
|
|
||||||
// AddNamespace register Namespace into beego.Handler
|
// AddNamespace register Namespace into beego.Handler
|
||||||
// support multi Namespace
|
// support multi Namespace
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func AddNamespace(nl ...*Namespace) {
|
func AddNamespace(nl ...*Namespace) {
|
||||||
for _, n := range nl {
|
for _, n := range nl {
|
||||||
for k, v := range n.handlers.routers {
|
for k, v := range n.handlers.routers {
|
||||||
@ -276,6 +296,7 @@ func addPrefix(t *Tree, prefix string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSCond is Namespace Condition
|
// NSCond is Namespace Condition
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSCond(cond namespaceCond) LinkNamespace {
|
func NSCond(cond namespaceCond) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Cond(cond)
|
ns.Cond(cond)
|
||||||
@ -283,6 +304,7 @@ func NSCond(cond namespaceCond) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSBefore Namespace BeforeRouter filter
|
// NSBefore Namespace BeforeRouter filter
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSBefore(filterList ...FilterFunc) LinkNamespace {
|
func NSBefore(filterList ...FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Filter("before", filterList...)
|
ns.Filter("before", filterList...)
|
||||||
@ -290,6 +312,7 @@ func NSBefore(filterList ...FilterFunc) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSAfter add Namespace FinishRouter filter
|
// NSAfter add Namespace FinishRouter filter
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSAfter(filterList ...FilterFunc) LinkNamespace {
|
func NSAfter(filterList ...FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Filter("after", filterList...)
|
ns.Filter("after", filterList...)
|
||||||
@ -297,6 +320,7 @@ func NSAfter(filterList ...FilterFunc) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSInclude Namespace Include ControllerInterface
|
// NSInclude Namespace Include ControllerInterface
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSInclude(cList ...ControllerInterface) LinkNamespace {
|
func NSInclude(cList ...ControllerInterface) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Include(cList...)
|
ns.Include(cList...)
|
||||||
@ -304,6 +328,7 @@ func NSInclude(cList ...ControllerInterface) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSRouter call Namespace Router
|
// NSRouter call Namespace Router
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSRouter(rootpath string, c ControllerInterface, mappingMethods ...string) LinkNamespace {
|
func NSRouter(rootpath string, c ControllerInterface, mappingMethods ...string) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Router(rootpath, c, mappingMethods...)
|
ns.Router(rootpath, c, mappingMethods...)
|
||||||
@ -311,6 +336,7 @@ func NSRouter(rootpath string, c ControllerInterface, mappingMethods ...string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSGet call Namespace Get
|
// NSGet call Namespace Get
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSGet(rootpath string, f FilterFunc) LinkNamespace {
|
func NSGet(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Get(rootpath, f)
|
ns.Get(rootpath, f)
|
||||||
@ -318,6 +344,7 @@ func NSGet(rootpath string, f FilterFunc) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSPost call Namespace Post
|
// NSPost call Namespace Post
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSPost(rootpath string, f FilterFunc) LinkNamespace {
|
func NSPost(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Post(rootpath, f)
|
ns.Post(rootpath, f)
|
||||||
@ -325,6 +352,7 @@ func NSPost(rootpath string, f FilterFunc) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSHead call Namespace Head
|
// NSHead call Namespace Head
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSHead(rootpath string, f FilterFunc) LinkNamespace {
|
func NSHead(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Head(rootpath, f)
|
ns.Head(rootpath, f)
|
||||||
@ -332,6 +360,7 @@ func NSHead(rootpath string, f FilterFunc) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSPut call Namespace Put
|
// NSPut call Namespace Put
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSPut(rootpath string, f FilterFunc) LinkNamespace {
|
func NSPut(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Put(rootpath, f)
|
ns.Put(rootpath, f)
|
||||||
@ -339,6 +368,7 @@ func NSPut(rootpath string, f FilterFunc) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSDelete call Namespace Delete
|
// NSDelete call Namespace Delete
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSDelete(rootpath string, f FilterFunc) LinkNamespace {
|
func NSDelete(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Delete(rootpath, f)
|
ns.Delete(rootpath, f)
|
||||||
@ -346,6 +376,7 @@ func NSDelete(rootpath string, f FilterFunc) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSAny call Namespace Any
|
// NSAny call Namespace Any
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSAny(rootpath string, f FilterFunc) LinkNamespace {
|
func NSAny(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Any(rootpath, f)
|
ns.Any(rootpath, f)
|
||||||
@ -353,6 +384,7 @@ func NSAny(rootpath string, f FilterFunc) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSOptions call Namespace Options
|
// NSOptions call Namespace Options
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSOptions(rootpath string, f FilterFunc) LinkNamespace {
|
func NSOptions(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Options(rootpath, f)
|
ns.Options(rootpath, f)
|
||||||
@ -360,6 +392,7 @@ func NSOptions(rootpath string, f FilterFunc) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSPatch call Namespace Patch
|
// NSPatch call Namespace Patch
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSPatch(rootpath string, f FilterFunc) LinkNamespace {
|
func NSPatch(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Patch(rootpath, f)
|
ns.Patch(rootpath, f)
|
||||||
@ -367,6 +400,7 @@ func NSPatch(rootpath string, f FilterFunc) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSAutoRouter call Namespace AutoRouter
|
// NSAutoRouter call Namespace AutoRouter
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSAutoRouter(c ControllerInterface) LinkNamespace {
|
func NSAutoRouter(c ControllerInterface) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.AutoRouter(c)
|
ns.AutoRouter(c)
|
||||||
@ -374,6 +408,7 @@ func NSAutoRouter(c ControllerInterface) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSAutoPrefix call Namespace AutoPrefix
|
// NSAutoPrefix call Namespace AutoPrefix
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSAutoPrefix(prefix string, c ControllerInterface) LinkNamespace {
|
func NSAutoPrefix(prefix string, c ControllerInterface) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.AutoPrefix(prefix, c)
|
ns.AutoPrefix(prefix, c)
|
||||||
@ -381,6 +416,7 @@ func NSAutoPrefix(prefix string, c ControllerInterface) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSNamespace add sub Namespace
|
// NSNamespace add sub Namespace
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSNamespace(prefix string, params ...LinkNamespace) LinkNamespace {
|
func NSNamespace(prefix string, params ...LinkNamespace) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
n := NewNamespace(prefix, params...)
|
n := NewNamespace(prefix, params...)
|
||||||
@ -389,6 +425,7 @@ func NSNamespace(prefix string, params ...LinkNamespace) LinkNamespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NSHandler add handler
|
// NSHandler add handler
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NSHandler(rootpath string, h http.Handler) LinkNamespace {
|
func NSHandler(rootpath string, h http.Handler) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Handler(rootpath, h)
|
ns.Handler(rootpath, h)
|
||||||
|
@ -21,9 +21,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// PolicyFunc defines a policy function which is invoked before the controller handler is executed.
|
// PolicyFunc defines a policy function which is invoked before the controller handler is executed.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type PolicyFunc func(*context.Context)
|
type PolicyFunc func(*context.Context)
|
||||||
|
|
||||||
// FindPolicy Find Router info for URL
|
// FindPolicy Find Router info for URL
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) FindPolicy(cont *context.Context) []PolicyFunc {
|
func (p *ControllerRegister) FindPolicy(cont *context.Context) []PolicyFunc {
|
||||||
var urlPath = cont.Input.URL()
|
var urlPath = cont.Input.URL()
|
||||||
if !BConfig.RouterCaseSensitive {
|
if !BConfig.RouterCaseSensitive {
|
||||||
@ -72,6 +74,7 @@ func (p *ControllerRegister) addToPolicy(method, pattern string, r ...PolicyFunc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Policy Register new policy in beego
|
// Policy Register new policy in beego
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Policy(pattern, method string, policy ...PolicyFunc) {
|
func Policy(pattern, method string, policy ...PolicyFunc) {
|
||||||
BeeApp.Handlers.addToPolicy(method, pattern, policy...)
|
BeeApp.Handlers.addToPolicy(method, pattern, policy...)
|
||||||
}
|
}
|
||||||
|
29
router.go
29
router.go
@ -51,6 +51,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// HTTPMETHOD list the supported http methods.
|
// HTTPMETHOD list the supported http methods.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
HTTPMETHOD = map[string]bool{
|
HTTPMETHOD = map[string]bool{
|
||||||
"GET": true,
|
"GET": true,
|
||||||
"POST": true,
|
"POST": true,
|
||||||
@ -80,10 +81,12 @@ var (
|
|||||||
|
|
||||||
urlPlaceholder = "{{placeholder}}"
|
urlPlaceholder = "{{placeholder}}"
|
||||||
// DefaultAccessLogFilter will skip the accesslog if return true
|
// DefaultAccessLogFilter will skip the accesslog if return true
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
DefaultAccessLogFilter FilterHandler = &logFilter{}
|
DefaultAccessLogFilter FilterHandler = &logFilter{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// FilterHandler is an interface for
|
// FilterHandler is an interface for
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type FilterHandler interface {
|
type FilterHandler interface {
|
||||||
Filter(*beecontext.Context) bool
|
Filter(*beecontext.Context) bool
|
||||||
}
|
}
|
||||||
@ -92,6 +95,7 @@ type FilterHandler interface {
|
|||||||
type logFilter struct {
|
type logFilter struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (l *logFilter) Filter(ctx *beecontext.Context) bool {
|
func (l *logFilter) Filter(ctx *beecontext.Context) bool {
|
||||||
requestPath := path.Clean(ctx.Request.URL.Path)
|
requestPath := path.Clean(ctx.Request.URL.Path)
|
||||||
if requestPath == "/favicon.ico" || requestPath == "/robots.txt" {
|
if requestPath == "/favicon.ico" || requestPath == "/robots.txt" {
|
||||||
@ -106,6 +110,7 @@ func (l *logFilter) Filter(ctx *beecontext.Context) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ExceptMethodAppend to append a slice's value into "exceptMethod", for controller's methods shouldn't reflect to AutoRouter
|
// ExceptMethodAppend to append a slice's value into "exceptMethod", for controller's methods shouldn't reflect to AutoRouter
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func ExceptMethodAppend(action string) {
|
func ExceptMethodAppend(action string) {
|
||||||
exceptMethod = append(exceptMethod, action)
|
exceptMethod = append(exceptMethod, action)
|
||||||
}
|
}
|
||||||
@ -122,11 +127,13 @@ type ControllerInfo struct {
|
|||||||
methodParams []*param.MethodParam
|
methodParams []*param.MethodParam
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (c *ControllerInfo) GetPattern() string {
|
func (c *ControllerInfo) GetPattern() string {
|
||||||
return c.pattern
|
return c.pattern
|
||||||
}
|
}
|
||||||
|
|
||||||
// ControllerRegister containers registered router rules, controller handlers and filters.
|
// ControllerRegister containers registered router rules, controller handlers and filters.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type ControllerRegister struct {
|
type ControllerRegister struct {
|
||||||
routers map[string]*Tree
|
routers map[string]*Tree
|
||||||
enablePolicy bool
|
enablePolicy bool
|
||||||
@ -137,6 +144,7 @@ type ControllerRegister struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewControllerRegister returns a new ControllerRegister.
|
// NewControllerRegister returns a new ControllerRegister.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NewControllerRegister() *ControllerRegister {
|
func NewControllerRegister() *ControllerRegister {
|
||||||
return &ControllerRegister{
|
return &ControllerRegister{
|
||||||
routers: make(map[string]*Tree),
|
routers: make(map[string]*Tree),
|
||||||
@ -159,6 +167,7 @@ func NewControllerRegister() *ControllerRegister {
|
|||||||
// Add("/api/delete",&RestController{},"delete:DeleteFood")
|
// Add("/api/delete",&RestController{},"delete:DeleteFood")
|
||||||
// Add("/api",&RestController{},"get,post:ApiFunc"
|
// Add("/api",&RestController{},"get,post:ApiFunc"
|
||||||
// Add("/simple",&SimpleController{},"get:GetFunc;post:PostFunc")
|
// Add("/simple",&SimpleController{},"get:GetFunc;post:PostFunc")
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) Add(pattern string, c ControllerInterface, mappingMethods ...string) {
|
func (p *ControllerRegister) Add(pattern string, c ControllerInterface, mappingMethods ...string) {
|
||||||
p.addWithMethodParams(pattern, c, nil, mappingMethods...)
|
p.addWithMethodParams(pattern, c, nil, mappingMethods...)
|
||||||
}
|
}
|
||||||
@ -251,6 +260,7 @@ func (p *ControllerRegister) addToRouter(method, pattern string, r *ControllerIn
|
|||||||
|
|
||||||
// Include only when the Runmode is dev will generate router file in the router/auto.go from the controller
|
// Include only when the Runmode is dev will generate router file in the router/auto.go from the controller
|
||||||
// Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})
|
// Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) Include(cList ...ControllerInterface) {
|
func (p *ControllerRegister) Include(cList ...ControllerInterface) {
|
||||||
if BConfig.RunMode == DEV {
|
if BConfig.RunMode == DEV {
|
||||||
skip := make(map[string]bool, 10)
|
skip := make(map[string]bool, 10)
|
||||||
@ -313,11 +323,13 @@ func (p *ControllerRegister) Include(cList ...ControllerInterface) {
|
|||||||
// ctx := p.GetContext()
|
// ctx := p.GetContext()
|
||||||
// ctx.Reset(w, q)
|
// ctx.Reset(w, q)
|
||||||
// defer p.GiveBackContext(ctx)
|
// defer p.GiveBackContext(ctx)
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) GetContext() *beecontext.Context {
|
func (p *ControllerRegister) GetContext() *beecontext.Context {
|
||||||
return p.pool.Get().(*beecontext.Context)
|
return p.pool.Get().(*beecontext.Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GiveBackContext put the ctx into pool so that it could be reuse
|
// GiveBackContext put the ctx into pool so that it could be reuse
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) GiveBackContext(ctx *beecontext.Context) {
|
func (p *ControllerRegister) GiveBackContext(ctx *beecontext.Context) {
|
||||||
// clear input cached data
|
// clear input cached data
|
||||||
ctx.Input.Clear()
|
ctx.Input.Clear()
|
||||||
@ -331,6 +343,7 @@ func (p *ControllerRegister) GiveBackContext(ctx *beecontext.Context) {
|
|||||||
// Get("/", func(ctx *context.Context){
|
// Get("/", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) Get(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Get(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("get", pattern, f)
|
p.AddMethod("get", pattern, f)
|
||||||
}
|
}
|
||||||
@ -340,6 +353,7 @@ func (p *ControllerRegister) Get(pattern string, f FilterFunc) {
|
|||||||
// Post("/api", func(ctx *context.Context){
|
// Post("/api", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) Post(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Post(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("post", pattern, f)
|
p.AddMethod("post", pattern, f)
|
||||||
}
|
}
|
||||||
@ -349,6 +363,7 @@ func (p *ControllerRegister) Post(pattern string, f FilterFunc) {
|
|||||||
// Put("/api/:id", func(ctx *context.Context){
|
// Put("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) Put(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Put(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("put", pattern, f)
|
p.AddMethod("put", pattern, f)
|
||||||
}
|
}
|
||||||
@ -358,6 +373,7 @@ func (p *ControllerRegister) Put(pattern string, f FilterFunc) {
|
|||||||
// Delete("/api/:id", func(ctx *context.Context){
|
// Delete("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) Delete(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Delete(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("delete", pattern, f)
|
p.AddMethod("delete", pattern, f)
|
||||||
}
|
}
|
||||||
@ -367,6 +383,7 @@ func (p *ControllerRegister) Delete(pattern string, f FilterFunc) {
|
|||||||
// Head("/api/:id", func(ctx *context.Context){
|
// Head("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) Head(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Head(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("head", pattern, f)
|
p.AddMethod("head", pattern, f)
|
||||||
}
|
}
|
||||||
@ -376,6 +393,7 @@ func (p *ControllerRegister) Head(pattern string, f FilterFunc) {
|
|||||||
// Patch("/api/:id", func(ctx *context.Context){
|
// Patch("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) Patch(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Patch(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("patch", pattern, f)
|
p.AddMethod("patch", pattern, f)
|
||||||
}
|
}
|
||||||
@ -385,6 +403,7 @@ func (p *ControllerRegister) Patch(pattern string, f FilterFunc) {
|
|||||||
// Options("/api/:id", func(ctx *context.Context){
|
// Options("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) Options(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Options(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("options", pattern, f)
|
p.AddMethod("options", pattern, f)
|
||||||
}
|
}
|
||||||
@ -394,6 +413,7 @@ func (p *ControllerRegister) Options(pattern string, f FilterFunc) {
|
|||||||
// Any("/api/:id", func(ctx *context.Context){
|
// Any("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) Any(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Any(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("*", pattern, f)
|
p.AddMethod("*", pattern, f)
|
||||||
}
|
}
|
||||||
@ -403,6 +423,7 @@ func (p *ControllerRegister) Any(pattern string, f FilterFunc) {
|
|||||||
// AddMethod("get","/api/:id", func(ctx *context.Context){
|
// AddMethod("get","/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) AddMethod(method, pattern string, f FilterFunc) {
|
func (p *ControllerRegister) AddMethod(method, pattern string, f FilterFunc) {
|
||||||
method = strings.ToUpper(method)
|
method = strings.ToUpper(method)
|
||||||
if method != "*" && !HTTPMETHOD[method] {
|
if method != "*" && !HTTPMETHOD[method] {
|
||||||
@ -433,6 +454,7 @@ func (p *ControllerRegister) AddMethod(method, pattern string, f FilterFunc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handler add user defined Handler
|
// Handler add user defined Handler
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) Handler(pattern string, h http.Handler, options ...interface{}) {
|
func (p *ControllerRegister) Handler(pattern string, h http.Handler, options ...interface{}) {
|
||||||
route := &ControllerInfo{}
|
route := &ControllerInfo{}
|
||||||
route.pattern = pattern
|
route.pattern = pattern
|
||||||
@ -453,6 +475,7 @@ func (p *ControllerRegister) Handler(pattern string, h http.Handler, options ...
|
|||||||
// MainController has method List and Page.
|
// MainController has method List and Page.
|
||||||
// visit the url /main/list to execute List function
|
// visit the url /main/list to execute List function
|
||||||
// /main/page to execute Page function.
|
// /main/page to execute Page function.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) AddAuto(c ControllerInterface) {
|
func (p *ControllerRegister) AddAuto(c ControllerInterface) {
|
||||||
p.AddAutoPrefix("/", c)
|
p.AddAutoPrefix("/", c)
|
||||||
}
|
}
|
||||||
@ -462,6 +485,7 @@ func (p *ControllerRegister) AddAuto(c ControllerInterface) {
|
|||||||
// MainController has method List and Page.
|
// MainController has method List and Page.
|
||||||
// visit the url /admin/main/list to execute List function
|
// visit the url /admin/main/list to execute List function
|
||||||
// /admin/main/page to execute Page function.
|
// /admin/main/page to execute Page function.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) AddAutoPrefix(prefix string, c ControllerInterface) {
|
func (p *ControllerRegister) AddAutoPrefix(prefix string, c ControllerInterface) {
|
||||||
reflectVal := reflect.ValueOf(c)
|
reflectVal := reflect.ValueOf(c)
|
||||||
rt := reflectVal.Type()
|
rt := reflectVal.Type()
|
||||||
@ -492,6 +516,7 @@ func (p *ControllerRegister) AddAutoPrefix(prefix string, c ControllerInterface)
|
|||||||
// params is for:
|
// params is for:
|
||||||
// 1. setting the returnOnOutput value (false allows multiple filters to execute)
|
// 1. setting the returnOnOutput value (false allows multiple filters to execute)
|
||||||
// 2. determining whether or not params need to be reset.
|
// 2. determining whether or not params need to be reset.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) error {
|
func (p *ControllerRegister) InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) error {
|
||||||
mr := &FilterRouter{
|
mr := &FilterRouter{
|
||||||
tree: NewTree(),
|
tree: NewTree(),
|
||||||
@ -526,6 +551,7 @@ func (p *ControllerRegister) insertFilterRouter(pos int, mr *FilterRouter) (err
|
|||||||
|
|
||||||
// URLFor does another controller handler in this request function.
|
// URLFor does another controller handler in this request function.
|
||||||
// it can access any controller method.
|
// it can access any controller method.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) URLFor(endpoint string, values ...interface{}) string {
|
func (p *ControllerRegister) URLFor(endpoint string, values ...interface{}) string {
|
||||||
paths := strings.Split(endpoint, ".")
|
paths := strings.Split(endpoint, ".")
|
||||||
if len(paths) <= 1 {
|
if len(paths) <= 1 {
|
||||||
@ -695,6 +721,7 @@ func (p *ControllerRegister) execFilter(context *beecontext.Context, urlPath str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implement http.Handler interface.
|
// Implement http.Handler interface.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
var (
|
var (
|
||||||
@ -993,6 +1020,7 @@ func (p *ControllerRegister) handleParamResponse(context *beecontext.Context, ex
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FindRouter Find Router info for URL
|
// FindRouter Find Router info for URL
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (p *ControllerRegister) FindRouter(context *beecontext.Context) (routerInfo *ControllerInfo, isFind bool) {
|
func (p *ControllerRegister) FindRouter(context *beecontext.Context) (routerInfo *ControllerInfo, isFind bool) {
|
||||||
var urlPath = context.Input.URL()
|
var urlPath = context.Input.URL()
|
||||||
if !BConfig.RouterCaseSensitive {
|
if !BConfig.RouterCaseSensitive {
|
||||||
@ -1020,6 +1048,7 @@ func toURL(params map[string]string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LogAccess logging info HTTP Access
|
// LogAccess logging info HTTP Access
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func LogAccess(ctx *beecontext.Context, startTime *time.Time, statusCode int) {
|
func LogAccess(ctx *beecontext.Context, startTime *time.Time, statusCode int) {
|
||||||
// Skip logging if AccessLogs config is false
|
// Skip logging if AccessLogs config is false
|
||||||
if !BConfig.Log.AccessLogs {
|
if !BConfig.Log.AccessLogs {
|
||||||
|
11
template.go
11
template.go
@ -47,6 +47,7 @@ var (
|
|||||||
// ExecuteTemplate applies the template with name to the specified data object,
|
// ExecuteTemplate applies the template with name to the specified data object,
|
||||||
// writing the output to wr.
|
// writing the output to wr.
|
||||||
// A template will be executed safely in parallel.
|
// A template will be executed safely in parallel.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
|
func ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
|
||||||
return ExecuteViewPathTemplate(wr, name, BConfig.WebConfig.ViewsPath, data)
|
return ExecuteViewPathTemplate(wr, name, BConfig.WebConfig.ViewsPath, data)
|
||||||
}
|
}
|
||||||
@ -54,6 +55,7 @@ func ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
|
|||||||
// ExecuteViewPathTemplate applies the template with name and from specific viewPath to the specified data object,
|
// ExecuteViewPathTemplate applies the template with name and from specific viewPath to the specified data object,
|
||||||
// writing the output to wr.
|
// writing the output to wr.
|
||||||
// A template will be executed safely in parallel.
|
// A template will be executed safely in parallel.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func ExecuteViewPathTemplate(wr io.Writer, name string, viewPath string, data interface{}) error {
|
func ExecuteViewPathTemplate(wr io.Writer, name string, viewPath string, data interface{}) error {
|
||||||
if BConfig.RunMode == DEV {
|
if BConfig.RunMode == DEV {
|
||||||
templatesLock.RLock()
|
templatesLock.RLock()
|
||||||
@ -143,6 +145,7 @@ func (tf *templateFile) visit(paths string, f os.FileInfo, err error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HasTemplateExt return this path contains supported template extension of beego or not.
|
// HasTemplateExt return this path contains supported template extension of beego or not.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func HasTemplateExt(paths string) bool {
|
func HasTemplateExt(paths string) bool {
|
||||||
for _, v := range beeTemplateExt {
|
for _, v := range beeTemplateExt {
|
||||||
if strings.HasSuffix(paths, "."+v) {
|
if strings.HasSuffix(paths, "."+v) {
|
||||||
@ -153,6 +156,7 @@ func HasTemplateExt(paths string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddTemplateExt add new extension for template.
|
// AddTemplateExt add new extension for template.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func AddTemplateExt(ext string) {
|
func AddTemplateExt(ext string) {
|
||||||
for _, v := range beeTemplateExt {
|
for _, v := range beeTemplateExt {
|
||||||
if v == ext {
|
if v == ext {
|
||||||
@ -165,6 +169,7 @@ func AddTemplateExt(ext string) {
|
|||||||
// AddViewPath adds a new path to the supported view paths.
|
// AddViewPath adds a new path to the supported view paths.
|
||||||
//Can later be used by setting a controller ViewPath to this folder
|
//Can later be used by setting a controller ViewPath to this folder
|
||||||
//will panic if called after beego.Run()
|
//will panic if called after beego.Run()
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func AddViewPath(viewPath string) error {
|
func AddViewPath(viewPath string) error {
|
||||||
if beeViewPathTemplateLocked {
|
if beeViewPathTemplateLocked {
|
||||||
if _, exist := beeViewPathTemplates[viewPath]; exist {
|
if _, exist := beeViewPathTemplates[viewPath]; exist {
|
||||||
@ -182,6 +187,7 @@ func lockViewPaths() {
|
|||||||
|
|
||||||
// BuildTemplate will build all template files in a directory.
|
// BuildTemplate will build all template files in a directory.
|
||||||
// it makes beego can render any template file in view directory.
|
// it makes beego can render any template file in view directory.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func BuildTemplate(dir string, files ...string) error {
|
func BuildTemplate(dir string, files ...string) error {
|
||||||
var err error
|
var err error
|
||||||
fs := beeTemplateFS()
|
fs := beeTemplateFS()
|
||||||
@ -363,11 +369,13 @@ func defaultFSFunc() http.FileSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetTemplateFSFunc set default filesystem function
|
// SetTemplateFSFunc set default filesystem function
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func SetTemplateFSFunc(fnt templateFSFunc) {
|
func SetTemplateFSFunc(fnt templateFSFunc) {
|
||||||
beeTemplateFS = fnt
|
beeTemplateFS = fnt
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetViewsPath sets view directory path in beego application.
|
// SetViewsPath sets view directory path in beego application.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func SetViewsPath(path string) *App {
|
func SetViewsPath(path string) *App {
|
||||||
BConfig.WebConfig.ViewsPath = path
|
BConfig.WebConfig.ViewsPath = path
|
||||||
return BeeApp
|
return BeeApp
|
||||||
@ -375,6 +383,7 @@ func SetViewsPath(path string) *App {
|
|||||||
|
|
||||||
// SetStaticPath sets static directory path and proper url pattern in beego application.
|
// SetStaticPath sets static directory path and proper url pattern in beego application.
|
||||||
// if beego.SetStaticPath("static","public"), visit /static/* to load static file in folder "public".
|
// if beego.SetStaticPath("static","public"), visit /static/* to load static file in folder "public".
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func SetStaticPath(url string, path string) *App {
|
func SetStaticPath(url string, path string) *App {
|
||||||
if !strings.HasPrefix(url, "/") {
|
if !strings.HasPrefix(url, "/") {
|
||||||
url = "/" + url
|
url = "/" + url
|
||||||
@ -387,6 +396,7 @@ func SetStaticPath(url string, path string) *App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DelStaticPath removes the static folder setting in this url pattern in beego application.
|
// DelStaticPath removes the static folder setting in this url pattern in beego application.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func DelStaticPath(url string) *App {
|
func DelStaticPath(url string) *App {
|
||||||
if !strings.HasPrefix(url, "/") {
|
if !strings.HasPrefix(url, "/") {
|
||||||
url = "/" + url
|
url = "/" + url
|
||||||
@ -399,6 +409,7 @@ func DelStaticPath(url string) *App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddTemplateEngine add a new templatePreProcessor which support extension
|
// AddTemplateEngine add a new templatePreProcessor which support extension
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func AddTemplateEngine(extension string, fn templatePreProcessor) *App {
|
func AddTemplateEngine(extension string, fn templatePreProcessor) *App {
|
||||||
AddTemplateExt(extension)
|
AddTemplateExt(extension)
|
||||||
beeTemplateEngines[extension] = fn
|
beeTemplateEngines[extension] = fn
|
||||||
|
@ -35,6 +35,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Substr returns the substr from start to length.
|
// Substr returns the substr from start to length.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Substr(s string, start, length int) string {
|
func Substr(s string, start, length int) string {
|
||||||
bt := []rune(s)
|
bt := []rune(s)
|
||||||
if start < 0 {
|
if start < 0 {
|
||||||
@ -53,6 +54,7 @@ func Substr(s string, start, length int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HTML2str returns escaping text convert from html.
|
// HTML2str returns escaping text convert from html.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func HTML2str(html string) string {
|
func HTML2str(html string) string {
|
||||||
|
|
||||||
re := regexp.MustCompile(`\<[\S\s]+?\>`)
|
re := regexp.MustCompile(`\<[\S\s]+?\>`)
|
||||||
@ -76,6 +78,7 @@ func HTML2str(html string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DateFormat takes a time and a layout string and returns a string with the formatted date. Used by the template parser as "dateformat"
|
// DateFormat takes a time and a layout string and returns a string with the formatted date. Used by the template parser as "dateformat"
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func DateFormat(t time.Time, layout string) (datestring string) {
|
func DateFormat(t time.Time, layout string) (datestring string) {
|
||||||
datestring = t.Format(layout)
|
datestring = t.Format(layout)
|
||||||
return
|
return
|
||||||
@ -123,6 +126,7 @@ var datePatterns = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DateParse Parse Date use PHP time format.
|
// DateParse Parse Date use PHP time format.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func DateParse(dateString, format string) (time.Time, error) {
|
func DateParse(dateString, format string) (time.Time, error) {
|
||||||
replacer := strings.NewReplacer(datePatterns...)
|
replacer := strings.NewReplacer(datePatterns...)
|
||||||
format = replacer.Replace(format)
|
format = replacer.Replace(format)
|
||||||
@ -130,6 +134,7 @@ func DateParse(dateString, format string) (time.Time, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Date takes a PHP like date func to Go's time format.
|
// Date takes a PHP like date func to Go's time format.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Date(t time.Time, format string) string {
|
func Date(t time.Time, format string) string {
|
||||||
replacer := strings.NewReplacer(datePatterns...)
|
replacer := strings.NewReplacer(datePatterns...)
|
||||||
format = replacer.Replace(format)
|
format = replacer.Replace(format)
|
||||||
@ -138,6 +143,7 @@ func Date(t time.Time, format string) string {
|
|||||||
|
|
||||||
// Compare is a quick and dirty comparison function. It will convert whatever you give it to strings and see if the two values are equal.
|
// Compare is a quick and dirty comparison function. It will convert whatever you give it to strings and see if the two values are equal.
|
||||||
// Whitespace is trimmed. Used by the template parser as "eq".
|
// Whitespace is trimmed. Used by the template parser as "eq".
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Compare(a, b interface{}) (equal bool) {
|
func Compare(a, b interface{}) (equal bool) {
|
||||||
equal = false
|
equal = false
|
||||||
if strings.TrimSpace(fmt.Sprintf("%v", a)) == strings.TrimSpace(fmt.Sprintf("%v", b)) {
|
if strings.TrimSpace(fmt.Sprintf("%v", a)) == strings.TrimSpace(fmt.Sprintf("%v", b)) {
|
||||||
@ -147,16 +153,19 @@ func Compare(a, b interface{}) (equal bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CompareNot !Compare
|
// CompareNot !Compare
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func CompareNot(a, b interface{}) (equal bool) {
|
func CompareNot(a, b interface{}) (equal bool) {
|
||||||
return !Compare(a, b)
|
return !Compare(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotNil the same as CompareNot
|
// NotNil the same as CompareNot
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NotNil(a interface{}) (isNil bool) {
|
func NotNil(a interface{}) (isNil bool) {
|
||||||
return CompareNot(a, nil)
|
return CompareNot(a, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConfig get the Appconfig
|
// GetConfig get the Appconfig
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func GetConfig(returnType, key string, defaultVal interface{}) (value interface{}, err error) {
|
func GetConfig(returnType, key string, defaultVal interface{}) (value interface{}, err error) {
|
||||||
switch returnType {
|
switch returnType {
|
||||||
case "String":
|
case "String":
|
||||||
@ -195,11 +204,13 @@ func GetConfig(returnType, key string, defaultVal interface{}) (value interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Str2html Convert string to template.HTML type.
|
// Str2html Convert string to template.HTML type.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Str2html(raw string) template.HTML {
|
func Str2html(raw string) template.HTML {
|
||||||
return template.HTML(raw)
|
return template.HTML(raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Htmlquote returns quoted html string.
|
// Htmlquote returns quoted html string.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Htmlquote(text string) string {
|
func Htmlquote(text string) string {
|
||||||
//HTML编码为实体符号
|
//HTML编码为实体符号
|
||||||
/*
|
/*
|
||||||
@ -219,6 +230,7 @@ func Htmlquote(text string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Htmlunquote returns unquoted html string.
|
// Htmlunquote returns unquoted html string.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func Htmlunquote(text string) string {
|
func Htmlunquote(text string) string {
|
||||||
//实体符号解释为HTML
|
//实体符号解释为HTML
|
||||||
/*
|
/*
|
||||||
@ -249,11 +261,13 @@ func Htmlunquote(text string) string {
|
|||||||
// /user/John%20Doe
|
// /user/John%20Doe
|
||||||
//
|
//
|
||||||
// more detail http://beego.me/docs/mvc/controller/urlbuilding.md
|
// more detail http://beego.me/docs/mvc/controller/urlbuilding.md
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func URLFor(endpoint string, values ...interface{}) string {
|
func URLFor(endpoint string, values ...interface{}) string {
|
||||||
return BeeApp.Handlers.URLFor(endpoint, values...)
|
return BeeApp.Handlers.URLFor(endpoint, values...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AssetsJs returns script tag with src string.
|
// AssetsJs returns script tag with src string.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func AssetsJs(text string) template.HTML {
|
func AssetsJs(text string) template.HTML {
|
||||||
|
|
||||||
text = "<script src=\"" + text + "\"></script>"
|
text = "<script src=\"" + text + "\"></script>"
|
||||||
@ -262,6 +276,7 @@ func AssetsJs(text string) template.HTML {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AssetsCSS returns stylesheet link tag with src string.
|
// AssetsCSS returns stylesheet link tag with src string.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func AssetsCSS(text string) template.HTML {
|
func AssetsCSS(text string) template.HTML {
|
||||||
|
|
||||||
text = "<link href=\"" + text + "\" rel=\"stylesheet\" />"
|
text = "<link href=\"" + text + "\" rel=\"stylesheet\" />"
|
||||||
@ -411,6 +426,7 @@ func parseFormToStruct(form url.Values, objT reflect.Type, objV reflect.Value) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParseForm will parse form values to struct via tag.
|
// ParseForm will parse form values to struct via tag.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func ParseForm(form url.Values, obj interface{}) error {
|
func ParseForm(form url.Values, obj interface{}) error {
|
||||||
objT := reflect.TypeOf(obj)
|
objT := reflect.TypeOf(obj)
|
||||||
objV := reflect.ValueOf(obj)
|
objV := reflect.ValueOf(obj)
|
||||||
@ -442,6 +458,7 @@ var unKind = map[reflect.Kind]bool{
|
|||||||
|
|
||||||
// RenderForm will render object to form html.
|
// RenderForm will render object to form html.
|
||||||
// obj must be a struct pointer.
|
// obj must be a struct pointer.
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func RenderForm(obj interface{}) template.HTML {
|
func RenderForm(obj interface{}) template.HTML {
|
||||||
objT := reflect.TypeOf(obj)
|
objT := reflect.TypeOf(obj)
|
||||||
objV := reflect.ValueOf(obj)
|
objV := reflect.ValueOf(obj)
|
||||||
@ -715,6 +732,7 @@ func ge(arg1, arg2 interface{}) (bool, error) {
|
|||||||
//
|
//
|
||||||
// {{ map_get m "a" }} // return 1
|
// {{ map_get m "a" }} // return 1
|
||||||
// {{ map_get m 1 "c" }} // return 4
|
// {{ map_get m 1 "c" }} // return 4
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func MapGet(arg1 interface{}, arg2 ...interface{}) (interface{}, error) {
|
func MapGet(arg1 interface{}, arg2 ...interface{}) (interface{}, error) {
|
||||||
arg1Type := reflect.TypeOf(arg1)
|
arg1Type := reflect.TypeOf(arg1)
|
||||||
arg1Val := reflect.ValueOf(arg1)
|
arg1Val := reflect.ValueOf(arg1)
|
||||||
|
5
tree.go
5
tree.go
@ -31,6 +31,7 @@ var (
|
|||||||
// fixRouter stores Fixed Router
|
// fixRouter stores Fixed Router
|
||||||
// wildcard stores params
|
// wildcard stores params
|
||||||
// leaves store the endpoint information
|
// leaves store the endpoint information
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
type Tree struct {
|
type Tree struct {
|
||||||
//prefix set for static router
|
//prefix set for static router
|
||||||
prefix string
|
prefix string
|
||||||
@ -43,12 +44,14 @@ type Tree struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTree return a new Tree
|
// NewTree return a new Tree
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func NewTree() *Tree {
|
func NewTree() *Tree {
|
||||||
return &Tree{}
|
return &Tree{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTree will add tree to the exist Tree
|
// AddTree will add tree to the exist Tree
|
||||||
// prefix should has no params
|
// prefix should has no params
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (t *Tree) AddTree(prefix string, tree *Tree) {
|
func (t *Tree) AddTree(prefix string, tree *Tree) {
|
||||||
t.addtree(splitPath(prefix), tree, nil, "")
|
t.addtree(splitPath(prefix), tree, nil, "")
|
||||||
}
|
}
|
||||||
@ -200,6 +203,7 @@ func filterTreeWithPrefix(t *Tree, wildcards []string, reg string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddRouter call addseg function
|
// AddRouter call addseg function
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (t *Tree) AddRouter(pattern string, runObject interface{}) {
|
func (t *Tree) AddRouter(pattern string, runObject interface{}) {
|
||||||
t.addseg(splitPath(pattern), runObject, nil, "")
|
t.addseg(splitPath(pattern), runObject, nil, "")
|
||||||
}
|
}
|
||||||
@ -283,6 +287,7 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Match router to runObject & params
|
// Match router to runObject & params
|
||||||
|
// Deprecated: using pkg/, we will delete this in v2.1.0
|
||||||
func (t *Tree) Match(pattern string, ctx *context.Context) (runObject interface{}) {
|
func (t *Tree) Match(pattern string, ctx *context.Context) (runObject interface{}) {
|
||||||
if len(pattern) == 0 || pattern[0] != '/' {
|
if len(pattern) == 0 || pattern[0] != '/' {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user