mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 19:10:54 +00:00
make golint happy
This commit is contained in:
parent
61570ac2f7
commit
67b36d7c48
@ -88,8 +88,8 @@ type ControllerInterface interface {
|
|||||||
Options()
|
Options()
|
||||||
Finish()
|
Finish()
|
||||||
Render() error
|
Render() error
|
||||||
XsrfToken() string
|
XSRFToken() string
|
||||||
CheckXsrfCookie() bool
|
CheckXSRFCookie() bool
|
||||||
HandlerFunc(fn string) bool
|
HandlerFunc(fn string) bool
|
||||||
URLMapping()
|
URLMapping()
|
||||||
}
|
}
|
||||||
|
2
doc.go
2
doc.go
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
Package beego provide a MVC framework
|
||||||
beego: an open-source, high-performance, modular, full-stack web framework
|
beego: an open-source, high-performance, modular, full-stack web framework
|
||||||
|
|
||||||
It is used for rapid development of RESTful APIs, web apps and backend services in Go.
|
It is used for rapid development of RESTful APIs, web apps and backend services in Go.
|
||||||
@ -14,4 +15,3 @@ beego is inspired by Tornado, Sinatra and Flask with the added benefit of some G
|
|||||||
more infomation: http://beego.me
|
more infomation: http://beego.me
|
||||||
*/
|
*/
|
||||||
package beego
|
package beego
|
||||||
|
|
||||||
|
9
docs.go
9
docs.go
@ -20,20 +20,21 @@ import (
|
|||||||
"github.com/astaxie/beego/context"
|
"github.com/astaxie/beego/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
var GlobalDocApi map[string]interface{}
|
// GlobalDocAPI store the swagger api documents
|
||||||
|
var GlobalDocAPI map[string]interface{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if EnableDocs {
|
if EnableDocs {
|
||||||
GlobalDocApi = make(map[string]interface{})
|
GlobalDocAPI = make(map[string]interface{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func serverDocs(ctx *context.Context) {
|
func serverDocs(ctx *context.Context) {
|
||||||
var obj interface{}
|
var obj interface{}
|
||||||
if splat := ctx.Input.Param(":splat"); splat == "" {
|
if splat := ctx.Input.Param(":splat"); splat == "" {
|
||||||
obj = GlobalDocApi["Root"]
|
obj = GlobalDocAPI["Root"]
|
||||||
} else {
|
} else {
|
||||||
if v, ok := GlobalDocApi[splat]; ok {
|
if v, ok := GlobalDocAPI[splat]; ok {
|
||||||
obj = v
|
obj = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
error.go
6
error.go
@ -362,7 +362,7 @@ func gatewayTimeout(rw http.ResponseWriter, r *http.Request) {
|
|||||||
// usage:
|
// usage:
|
||||||
// beego.ErrorHandler("404",NotFound)
|
// beego.ErrorHandler("404",NotFound)
|
||||||
// beego.ErrorHandler("500",InternalServerError)
|
// beego.ErrorHandler("500",InternalServerError)
|
||||||
func Errorhandler(code string, h http.HandlerFunc) *App {
|
func ErrorHandler(code string, h http.HandlerFunc) *App {
|
||||||
errinfo := &errorInfo{}
|
errinfo := &errorInfo{}
|
||||||
errinfo.errorType = errorTypeHandler
|
errinfo.errorType = errorTypeHandler
|
||||||
errinfo.handler = h
|
errinfo.handler = h
|
||||||
@ -373,7 +373,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.ErrorHandler(&controllers.ErrorController{})
|
// beego.ErrorController(&controllers.ErrorController{})
|
||||||
func ErrorController(c ControllerInterface) *App {
|
func ErrorController(c ControllerInterface) *App {
|
||||||
reflectVal := reflect.ValueOf(c)
|
reflectVal := reflect.ValueOf(c)
|
||||||
rt := reflectVal.Type()
|
rt := reflectVal.Type()
|
||||||
@ -431,7 +431,7 @@ func executeError(err *errorInfo, ctx *context.Context, code int) {
|
|||||||
|
|
||||||
execController.URLMapping()
|
execController.URLMapping()
|
||||||
|
|
||||||
in := make([]reflect.Value, 0)
|
var in []reflect.Value
|
||||||
method := vc.MethodByName(err.method)
|
method := vc.MethodByName(err.method)
|
||||||
method.Call(in)
|
method.Call(in)
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ func (f *FilterRouter) ValidRouter(url string) (bool, map[string]string) {
|
|||||||
}
|
}
|
||||||
if isok, ok := isok.(bool); ok {
|
if isok, ok := isok.(bool); ok {
|
||||||
return isok, params
|
return isok, params
|
||||||
} else {
|
|
||||||
return false, nil
|
|
||||||
}
|
}
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ func (t *TestFlashController) TestWriteFlash() {
|
|||||||
flash.Notice("TestFlashString")
|
flash.Notice("TestFlashString")
|
||||||
flash.Store(&t.Controller)
|
flash.Store(&t.Controller)
|
||||||
// we choose to serve json because we don't want to load a template html file
|
// we choose to serve json because we don't want to load a template html file
|
||||||
t.ServeJson(true)
|
t.ServeJSON(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlashHeader(t *testing.T) {
|
func TestFlashHeader(t *testing.T) {
|
||||||
|
20
hooks.go
20
hooks.go
@ -19,41 +19,41 @@ func registerMime() error {
|
|||||||
// register default error http handlers, 404,401,403,500 and 503.
|
// register default error http handlers, 404,401,403,500 and 503.
|
||||||
func registerDefaultErrorHandler() error {
|
func registerDefaultErrorHandler() error {
|
||||||
if _, ok := ErrorMaps["401"]; !ok {
|
if _, ok := ErrorMaps["401"]; !ok {
|
||||||
Errorhandler("401", unauthorized)
|
ErrorHandler("401", unauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := ErrorMaps["402"]; !ok {
|
if _, ok := ErrorMaps["402"]; !ok {
|
||||||
Errorhandler("402", paymentRequired)
|
ErrorHandler("402", paymentRequired)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := ErrorMaps["403"]; !ok {
|
if _, ok := ErrorMaps["403"]; !ok {
|
||||||
Errorhandler("403", forbidden)
|
ErrorHandler("403", forbidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := ErrorMaps["404"]; !ok {
|
if _, ok := ErrorMaps["404"]; !ok {
|
||||||
Errorhandler("404", notFound)
|
ErrorHandler("404", notFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := ErrorMaps["405"]; !ok {
|
if _, ok := ErrorMaps["405"]; !ok {
|
||||||
Errorhandler("405", methodNotAllowed)
|
ErrorHandler("405", methodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := ErrorMaps["500"]; !ok {
|
if _, ok := ErrorMaps["500"]; !ok {
|
||||||
Errorhandler("500", internalServerError)
|
ErrorHandler("500", internalServerError)
|
||||||
}
|
}
|
||||||
if _, ok := ErrorMaps["501"]; !ok {
|
if _, ok := ErrorMaps["501"]; !ok {
|
||||||
Errorhandler("501", notImplemented)
|
ErrorHandler("501", notImplemented)
|
||||||
}
|
}
|
||||||
if _, ok := ErrorMaps["502"]; !ok {
|
if _, ok := ErrorMaps["502"]; !ok {
|
||||||
Errorhandler("502", badGateway)
|
ErrorHandler("502", badGateway)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := ErrorMaps["503"]; !ok {
|
if _, ok := ErrorMaps["503"]; !ok {
|
||||||
Errorhandler("503", serviceUnavailable)
|
ErrorHandler("503", serviceUnavailable)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := ErrorMaps["504"]; !ok {
|
if _, ok := ErrorMaps["504"]; !ok {
|
||||||
Errorhandler("504", gatewayTimeout)
|
ErrorHandler("504", gatewayTimeout)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
15
log.go
15
log.go
@ -32,18 +32,18 @@ const (
|
|||||||
LevelDebug
|
LevelDebug
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetLogLevel sets the global log level used by the simple
|
// SetLevel sets the global log level used by the simple logger.
|
||||||
// logger.
|
|
||||||
func SetLevel(l int) {
|
func SetLevel(l int) {
|
||||||
BeeLogger.SetLevel(l)
|
BeeLogger.SetLevel(l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLogFuncCall set the CallDepth, default is 3
|
||||||
func SetLogFuncCall(b bool) {
|
func SetLogFuncCall(b bool) {
|
||||||
BeeLogger.EnableFuncCallDepth(b)
|
BeeLogger.EnableFuncCallDepth(b)
|
||||||
BeeLogger.SetLogFuncCallDepth(3)
|
BeeLogger.SetLogFuncCallDepth(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
// logger references the used application logger.
|
// BeeLogger references the used application logger.
|
||||||
var BeeLogger *logs.BeeLogger
|
var BeeLogger *logs.BeeLogger
|
||||||
|
|
||||||
// SetLogger sets a new logger.
|
// SetLogger sets a new logger.
|
||||||
@ -55,10 +55,12 @@ func SetLogger(adaptername string, config string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Emergency logs a message at emergency level.
|
||||||
func Emergency(v ...interface{}) {
|
func Emergency(v ...interface{}) {
|
||||||
BeeLogger.Emergency(generateFmtStr(len(v)), v...)
|
BeeLogger.Emergency(generateFmtStr(len(v)), v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Alert logs a message at alert level.
|
||||||
func Alert(v ...interface{}) {
|
func Alert(v ...interface{}) {
|
||||||
BeeLogger.Alert(generateFmtStr(len(v)), v...)
|
BeeLogger.Alert(generateFmtStr(len(v)), v...)
|
||||||
}
|
}
|
||||||
@ -78,21 +80,22 @@ func Warning(v ...interface{}) {
|
|||||||
BeeLogger.Warning(generateFmtStr(len(v)), v...)
|
BeeLogger.Warning(generateFmtStr(len(v)), v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// compatibility alias for Warning()
|
// Warn compatibility alias for Warning()
|
||||||
func Warn(v ...interface{}) {
|
func Warn(v ...interface{}) {
|
||||||
BeeLogger.Warn(generateFmtStr(len(v)), v...)
|
BeeLogger.Warn(generateFmtStr(len(v)), v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notice logs a message at notice level.
|
||||||
func Notice(v ...interface{}) {
|
func Notice(v ...interface{}) {
|
||||||
BeeLogger.Notice(generateFmtStr(len(v)), v...)
|
BeeLogger.Notice(generateFmtStr(len(v)), v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info logs a message at info level.
|
// Informational logs a message at info level.
|
||||||
func Informational(v ...interface{}) {
|
func Informational(v ...interface{}) {
|
||||||
BeeLogger.Informational(generateFmtStr(len(v)), v...)
|
BeeLogger.Informational(generateFmtStr(len(v)), v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// compatibility alias for Warning()
|
// Info compatibility alias for Warning()
|
||||||
func Info(v ...interface{}) {
|
func Info(v ...interface{}) {
|
||||||
BeeLogger.Info(generateFmtStr(len(v)), v...)
|
BeeLogger.Info(generateFmtStr(len(v)), v...)
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var gmfim map[string]*memFileInfo = make(map[string]*memFileInfo)
|
var (
|
||||||
var lock sync.RWMutex
|
gmfim = make(map[string]*memFileInfo)
|
||||||
|
lock sync.RWMutex
|
||||||
|
)
|
||||||
|
|
||||||
// OpenMemZipFile returns MemFile object with a compressed static file.
|
// OpenMemZipFile returns MemFile object with a compressed static file.
|
||||||
// it's used for serve static file if gzip enable.
|
// it's used for serve static file if gzip enable.
|
||||||
|
2
mime.go
2
mime.go
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
package beego
|
package beego
|
||||||
|
|
||||||
var mimemaps map[string]string = map[string]string{
|
var mimemaps = map[string]string{
|
||||||
".3dm": "x-world/x-3dmf",
|
".3dm": "x-world/x-3dmf",
|
||||||
".3dmf": "x-world/x-3dmf",
|
".3dmf": "x-world/x-3dmf",
|
||||||
".7z": "application/x-7z-compressed",
|
".7z": "application/x-7z-compressed",
|
||||||
|
105
namespace.go
105
namespace.go
@ -23,7 +23,8 @@ import (
|
|||||||
|
|
||||||
type namespaceCond func(*beecontext.Context) bool
|
type namespaceCond func(*beecontext.Context) bool
|
||||||
|
|
||||||
type innerNamespace func(*Namespace)
|
// LinkNamespace used as link action
|
||||||
|
type LinkNamespace func(*Namespace)
|
||||||
|
|
||||||
// Namespace is store all the info
|
// Namespace is store all the info
|
||||||
type Namespace struct {
|
type Namespace struct {
|
||||||
@ -31,8 +32,8 @@ type Namespace struct {
|
|||||||
handlers *ControllerRegister
|
handlers *ControllerRegister
|
||||||
}
|
}
|
||||||
|
|
||||||
// get new Namespace
|
// NewNamespace get new Namespace
|
||||||
func NewNamespace(prefix string, params ...innerNamespace) *Namespace {
|
func NewNamespace(prefix string, params ...LinkNamespace) *Namespace {
|
||||||
ns := &Namespace{
|
ns := &Namespace{
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
handlers: NewControllerRegister(),
|
handlers: NewControllerRegister(),
|
||||||
@ -43,7 +44,7 @@ func NewNamespace(prefix string, params ...innerNamespace) *Namespace {
|
|||||||
return ns
|
return ns
|
||||||
}
|
}
|
||||||
|
|
||||||
// set condtion function
|
// Cond set condtion function
|
||||||
// if cond return true can run this namespace, else can't
|
// if cond return true can run this namespace, else can't
|
||||||
// usage:
|
// usage:
|
||||||
// ns.Cond(func (ctx *context.Context) bool{
|
// ns.Cond(func (ctx *context.Context) bool{
|
||||||
@ -72,7 +73,7 @@ func (n *Namespace) Cond(cond namespaceCond) *Namespace {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
// add filter in the Namespace
|
// Filter add filter in the Namespace
|
||||||
// action has before & after
|
// action has before & after
|
||||||
// FilterFunc
|
// FilterFunc
|
||||||
// usage:
|
// usage:
|
||||||
@ -95,98 +96,98 @@ func (n *Namespace) Filter(action string, filter ...FilterFunc) *Namespace {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// nest Namespace
|
// Namespace add nest Namespace
|
||||||
// usage:
|
// usage:
|
||||||
//ns := beego.NewNamespace(“/v1”).
|
//ns := beego.NewNamespace(“/v1”).
|
||||||
//Namespace(
|
//Namespace(
|
||||||
@ -230,7 +231,7 @@ func (n *Namespace) Namespace(ns ...*Namespace) *Namespace {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
// register Namespace into beego.Handler
|
// AddNamespace register Namespace into beego.Handler
|
||||||
// support multi Namespace
|
// support multi Namespace
|
||||||
func AddNamespace(nl ...*Namespace) {
|
func AddNamespace(nl ...*Namespace) {
|
||||||
for _, n := range nl {
|
for _, n := range nl {
|
||||||
@ -275,113 +276,113 @@ func addPrefix(t *Tree, prefix string) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Condition
|
// NSCond is Namespace Condition
|
||||||
func NSCond(cond namespaceCond) innerNamespace {
|
func NSCond(cond namespaceCond) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Cond(cond)
|
ns.Cond(cond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace BeforeRouter filter
|
// NSBefore Namespace BeforeRouter filter
|
||||||
func NSBefore(filiterList ...FilterFunc) innerNamespace {
|
func NSBefore(filiterList ...FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Filter("before", filiterList...)
|
ns.Filter("before", filiterList...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace FinishRouter filter
|
// NSAfter add Namespace FinishRouter filter
|
||||||
func NSAfter(filiterList ...FilterFunc) innerNamespace {
|
func NSAfter(filiterList ...FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Filter("after", filiterList...)
|
ns.Filter("after", filiterList...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Include ControllerInterface
|
// NSInclude Namespace Include ControllerInterface
|
||||||
func NSInclude(cList ...ControllerInterface) innerNamespace {
|
func NSInclude(cList ...ControllerInterface) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Include(cList...)
|
ns.Include(cList...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Router
|
// NSRouter call Namespace Router
|
||||||
func NSRouter(rootpath string, c ControllerInterface, mappingMethods ...string) innerNamespace {
|
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...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Get
|
// NSGet call Namespace Get
|
||||||
func NSGet(rootpath string, f FilterFunc) innerNamespace {
|
func NSGet(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Get(rootpath, f)
|
ns.Get(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Post
|
// NSPost call Namespace Post
|
||||||
func NSPost(rootpath string, f FilterFunc) innerNamespace {
|
func NSPost(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Post(rootpath, f)
|
ns.Post(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Head
|
// NSHead call Namespace Head
|
||||||
func NSHead(rootpath string, f FilterFunc) innerNamespace {
|
func NSHead(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Head(rootpath, f)
|
ns.Head(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Put
|
// NSPut call Namespace Put
|
||||||
func NSPut(rootpath string, f FilterFunc) innerNamespace {
|
func NSPut(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Put(rootpath, f)
|
ns.Put(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Delete
|
// NSDelete call Namespace Delete
|
||||||
func NSDelete(rootpath string, f FilterFunc) innerNamespace {
|
func NSDelete(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Delete(rootpath, f)
|
ns.Delete(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Any
|
// NSAny call Namespace Any
|
||||||
func NSAny(rootpath string, f FilterFunc) innerNamespace {
|
func NSAny(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Any(rootpath, f)
|
ns.Any(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Options
|
// NSOptions call Namespace Options
|
||||||
func NSOptions(rootpath string, f FilterFunc) innerNamespace {
|
func NSOptions(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Options(rootpath, f)
|
ns.Options(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Patch
|
// NSPatch call Namespace Patch
|
||||||
func NSPatch(rootpath string, f FilterFunc) innerNamespace {
|
func NSPatch(rootpath string, f FilterFunc) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Patch(rootpath, f)
|
ns.Patch(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Namespace AutoRouter
|
// NSAutoRouter call Namespace AutoRouter
|
||||||
func NSAutoRouter(c ControllerInterface) innerNamespace {
|
func NSAutoRouter(c ControllerInterface) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.AutoRouter(c)
|
ns.AutoRouter(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace AutoPrefix
|
// NSAutoPrefix call Namespace AutoPrefix
|
||||||
func NSAutoPrefix(prefix string, c ControllerInterface) innerNamespace {
|
func NSAutoPrefix(prefix string, c ControllerInterface) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.AutoPrefix(prefix, c)
|
ns.AutoPrefix(prefix, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace add sub Namespace
|
// NSNamespace add sub Namespace
|
||||||
func NSNamespace(prefix string, params ...innerNamespace) innerNamespace {
|
func NSNamespace(prefix string, params ...LinkNamespace) LinkNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
n := NewNamespace(prefix, params...)
|
n := NewNamespace(prefix, params...)
|
||||||
ns.Namespace(n)
|
ns.Namespace(n)
|
||||||
|
@ -770,10 +770,10 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
//if XSRF is Enable then check cookie where there has any cookie in the request's cookie _csrf
|
//if XSRF is Enable then check cookie where there has any cookie in the request's cookie _csrf
|
||||||
if EnableXSRF {
|
if EnableXSRF {
|
||||||
execController.XsrfToken()
|
execController.XSRFToken()
|
||||||
if r.Method == "POST" || r.Method == "DELETE" || r.Method == "PUT" ||
|
if r.Method == "POST" || r.Method == "DELETE" || r.Method == "PUT" ||
|
||||||
(r.Method == "POST" && (context.Input.Query("_method") == "DELETE" || context.Input.Query("_method") == "PUT")) {
|
(r.Method == "POST" && (context.Input.Query("_method") == "DELETE" || context.Input.Query("_method") == "PUT")) {
|
||||||
execController.CheckXsrfCookie()
|
execController.CheckXSRFCookie()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ func (tc *TestController) Myext() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TestController) GetUrl() {
|
func (tc *TestController) GetUrl() {
|
||||||
tc.Ctx.Output.Body([]byte(tc.UrlFor(".Myext")))
|
tc.Ctx.Output.Body([]byte(tc.URLFor(".Myext")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TestController) GetParams() {
|
func (t *TestController) GetParams() {
|
||||||
@ -76,7 +76,7 @@ type JsonController struct {
|
|||||||
|
|
||||||
func (this *JsonController) Prepare() {
|
func (this *JsonController) Prepare() {
|
||||||
this.Data["json"] = "prepare"
|
this.Data["json"] = "prepare"
|
||||||
this.ServeJson(true)
|
this.ServeJSON(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *JsonController) Get() {
|
func (this *JsonController) Get() {
|
||||||
|
Loading…
Reference in New Issue
Block a user