From 67b36d7c487a163ce2496a9f7d38d6dc12090f36 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 8 Sep 2015 21:41:38 +0800 Subject: [PATCH] make golint happy --- controller.go | 4 +- doc.go | 2 +- docs.go | 9 +++-- error.go | 6 +-- filter.go | 3 +- flash_test.go | 2 +- hooks.go | 20 +++++----- log.go | 15 ++++--- memzipfile.go | 6 ++- mime.go | 2 +- namespace.go | 105 +++++++++++++++++++++++++------------------------ router.go | 4 +- router_test.go | 4 +- 13 files changed, 94 insertions(+), 88 deletions(-) diff --git a/controller.go b/controller.go index cad2b5ac..b225df03 100644 --- a/controller.go +++ b/controller.go @@ -88,8 +88,8 @@ type ControllerInterface interface { Options() Finish() Render() error - XsrfToken() string - CheckXsrfCookie() bool + XSRFToken() string + CheckXSRFCookie() bool HandlerFunc(fn string) bool URLMapping() } diff --git a/doc.go b/doc.go index 3a5b5cb8..4be305b3 100644 --- a/doc.go +++ b/doc.go @@ -1,4 +1,5 @@ /* +Package beego provide a MVC 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. @@ -14,4 +15,3 @@ beego is inspired by Tornado, Sinatra and Flask with the added benefit of some G more infomation: http://beego.me */ package beego - diff --git a/docs.go b/docs.go index aaad205e..1dbed6cc 100644 --- a/docs.go +++ b/docs.go @@ -20,20 +20,21 @@ import ( "github.com/astaxie/beego/context" ) -var GlobalDocApi map[string]interface{} +// GlobalDocAPI store the swagger api documents +var GlobalDocAPI map[string]interface{} func init() { if EnableDocs { - GlobalDocApi = make(map[string]interface{}) + GlobalDocAPI = make(map[string]interface{}) } } func serverDocs(ctx *context.Context) { var obj interface{} if splat := ctx.Input.Param(":splat"); splat == "" { - obj = GlobalDocApi["Root"] + obj = GlobalDocAPI["Root"] } else { - if v, ok := GlobalDocApi[splat]; ok { + if v, ok := GlobalDocAPI[splat]; ok { obj = v } } diff --git a/error.go b/error.go index f5c0c80b..b4708b30 100644 --- a/error.go +++ b/error.go @@ -362,7 +362,7 @@ func gatewayTimeout(rw http.ResponseWriter, r *http.Request) { // usage: // beego.ErrorHandler("404",NotFound) // beego.ErrorHandler("500",InternalServerError) -func Errorhandler(code string, h http.HandlerFunc) *App { +func ErrorHandler(code string, h http.HandlerFunc) *App { errinfo := &errorInfo{} errinfo.errorType = errorTypeHandler errinfo.handler = h @@ -373,7 +373,7 @@ func Errorhandler(code string, h http.HandlerFunc) *App { // ErrorController registers ControllerInterface to each http err code string. // usage: -// beego.ErrorHandler(&controllers.ErrorController{}) +// beego.ErrorController(&controllers.ErrorController{}) func ErrorController(c ControllerInterface) *App { reflectVal := reflect.ValueOf(c) rt := reflectVal.Type() @@ -431,7 +431,7 @@ func executeError(err *errorInfo, ctx *context.Context, code int) { execController.URLMapping() - in := make([]reflect.Value, 0) + var in []reflect.Value method := vc.MethodByName(err.method) method.Call(in) diff --git a/filter.go b/filter.go index f673ab66..7dbc7028 100644 --- a/filter.go +++ b/filter.go @@ -39,7 +39,6 @@ func (f *FilterRouter) ValidRouter(url string) (bool, map[string]string) { } if isok, ok := isok.(bool); ok { return isok, params - } else { - return false, nil } + return false, nil } diff --git a/flash_test.go b/flash_test.go index b655f552..640d54de 100644 --- a/flash_test.go +++ b/flash_test.go @@ -30,7 +30,7 @@ func (t *TestFlashController) TestWriteFlash() { flash.Notice("TestFlashString") flash.Store(&t.Controller) // 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) { diff --git a/hooks.go b/hooks.go index 3691a800..178d8dc4 100644 --- a/hooks.go +++ b/hooks.go @@ -19,41 +19,41 @@ func registerMime() error { // register default error http handlers, 404,401,403,500 and 503. func registerDefaultErrorHandler() error { if _, ok := ErrorMaps["401"]; !ok { - Errorhandler("401", unauthorized) + ErrorHandler("401", unauthorized) } if _, ok := ErrorMaps["402"]; !ok { - Errorhandler("402", paymentRequired) + ErrorHandler("402", paymentRequired) } if _, ok := ErrorMaps["403"]; !ok { - Errorhandler("403", forbidden) + ErrorHandler("403", forbidden) } if _, ok := ErrorMaps["404"]; !ok { - Errorhandler("404", notFound) + ErrorHandler("404", notFound) } if _, ok := ErrorMaps["405"]; !ok { - Errorhandler("405", methodNotAllowed) + ErrorHandler("405", methodNotAllowed) } if _, ok := ErrorMaps["500"]; !ok { - Errorhandler("500", internalServerError) + ErrorHandler("500", internalServerError) } if _, ok := ErrorMaps["501"]; !ok { - Errorhandler("501", notImplemented) + ErrorHandler("501", notImplemented) } if _, ok := ErrorMaps["502"]; !ok { - Errorhandler("502", badGateway) + ErrorHandler("502", badGateway) } if _, ok := ErrorMaps["503"]; !ok { - Errorhandler("503", serviceUnavailable) + ErrorHandler("503", serviceUnavailable) } if _, ok := ErrorMaps["504"]; !ok { - Errorhandler("504", gatewayTimeout) + ErrorHandler("504", gatewayTimeout) } return nil } diff --git a/log.go b/log.go index 7949ed96..68252236 100644 --- a/log.go +++ b/log.go @@ -32,18 +32,18 @@ const ( LevelDebug ) -// SetLogLevel sets the global log level used by the simple -// logger. +// SetLevel sets the global log level used by the simple logger. func SetLevel(l int) { BeeLogger.SetLevel(l) } +// SetLogFuncCall set the CallDepth, default is 3 func SetLogFuncCall(b bool) { BeeLogger.EnableFuncCallDepth(b) BeeLogger.SetLogFuncCallDepth(3) } -// logger references the used application logger. +// BeeLogger references the used application logger. var BeeLogger *logs.BeeLogger // SetLogger sets a new logger. @@ -55,10 +55,12 @@ func SetLogger(adaptername string, config string) error { return nil } +// Emergency logs a message at emergency level. func Emergency(v ...interface{}) { BeeLogger.Emergency(generateFmtStr(len(v)), v...) } +// Alert logs a message at alert level. func Alert(v ...interface{}) { BeeLogger.Alert(generateFmtStr(len(v)), v...) } @@ -78,21 +80,22 @@ func Warning(v ...interface{}) { BeeLogger.Warning(generateFmtStr(len(v)), v...) } -// compatibility alias for Warning() +// Warn compatibility alias for Warning() func Warn(v ...interface{}) { BeeLogger.Warn(generateFmtStr(len(v)), v...) } +// Notice logs a message at notice level. func Notice(v ...interface{}) { BeeLogger.Notice(generateFmtStr(len(v)), v...) } -// Info logs a message at info level. +// Informational logs a message at info level. func Informational(v ...interface{}) { BeeLogger.Informational(generateFmtStr(len(v)), v...) } -// compatibility alias for Warning() +// Info compatibility alias for Warning() func Info(v ...interface{}) { BeeLogger.Info(generateFmtStr(len(v)), v...) } diff --git a/memzipfile.go b/memzipfile.go index cc5e3851..0fff44b6 100644 --- a/memzipfile.go +++ b/memzipfile.go @@ -28,8 +28,10 @@ import ( "time" ) -var gmfim map[string]*memFileInfo = make(map[string]*memFileInfo) -var lock sync.RWMutex +var ( + gmfim = make(map[string]*memFileInfo) + lock sync.RWMutex +) // OpenMemZipFile returns MemFile object with a compressed static file. // it's used for serve static file if gzip enable. diff --git a/mime.go b/mime.go index 0034976e..e85fcb2a 100644 --- a/mime.go +++ b/mime.go @@ -14,7 +14,7 @@ package beego -var mimemaps map[string]string = map[string]string{ +var mimemaps = map[string]string{ ".3dm": "x-world/x-3dmf", ".3dmf": "x-world/x-3dmf", ".7z": "application/x-7z-compressed", diff --git a/namespace.go b/namespace.go index 86dc2ebd..0dfdd7af 100644 --- a/namespace.go +++ b/namespace.go @@ -23,7 +23,8 @@ import ( 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 type Namespace struct { @@ -31,8 +32,8 @@ type Namespace struct { handlers *ControllerRegister } -// get new Namespace -func NewNamespace(prefix string, params ...innerNamespace) *Namespace { +// NewNamespace get new Namespace +func NewNamespace(prefix string, params ...LinkNamespace) *Namespace { ns := &Namespace{ prefix: prefix, handlers: NewControllerRegister(), @@ -43,7 +44,7 @@ func NewNamespace(prefix string, params ...innerNamespace) *Namespace { return ns } -// set condtion function +// Cond set condtion function // if cond return true can run this namespace, else can't // usage: // ns.Cond(func (ctx *context.Context) bool{ @@ -72,7 +73,7 @@ func (n *Namespace) Cond(cond namespaceCond) *Namespace { return n } -// add filter in the Namespace +// Filter add filter in the Namespace // action has before & after // FilterFunc // usage: @@ -95,98 +96,98 @@ func (n *Namespace) Filter(action string, filter ...FilterFunc) *Namespace { return n } -// same as beego.Rourer +// Router same as beego.Rourer // refer: https://godoc.org/github.com/astaxie/beego#Router func (n *Namespace) Router(rootpath string, c ControllerInterface, mappingMethods ...string) *Namespace { n.handlers.Add(rootpath, c, mappingMethods...) return n } -// same as beego.AutoRouter +// AutoRouter same as beego.AutoRouter // refer: https://godoc.org/github.com/astaxie/beego#AutoRouter func (n *Namespace) AutoRouter(c ControllerInterface) *Namespace { n.handlers.AddAuto(c) return n } -// same as beego.AutoPrefix +// AutoPrefix same as beego.AutoPrefix // refer: https://godoc.org/github.com/astaxie/beego#AutoPrefix func (n *Namespace) AutoPrefix(prefix string, c ControllerInterface) *Namespace { n.handlers.AddAutoPrefix(prefix, c) return n } -// same as beego.Get +// Get same as beego.Get // refer: https://godoc.org/github.com/astaxie/beego#Get func (n *Namespace) Get(rootpath string, f FilterFunc) *Namespace { n.handlers.Get(rootpath, f) return n } -// same as beego.Post +// Post same as beego.Post // refer: https://godoc.org/github.com/astaxie/beego#Post func (n *Namespace) Post(rootpath string, f FilterFunc) *Namespace { n.handlers.Post(rootpath, f) return n } -// same as beego.Delete +// Delete same as beego.Delete // refer: https://godoc.org/github.com/astaxie/beego#Delete func (n *Namespace) Delete(rootpath string, f FilterFunc) *Namespace { n.handlers.Delete(rootpath, f) return n } -// same as beego.Put +// Put same as beego.Put // refer: https://godoc.org/github.com/astaxie/beego#Put func (n *Namespace) Put(rootpath string, f FilterFunc) *Namespace { n.handlers.Put(rootpath, f) return n } -// same as beego.Head +// Head same as beego.Head // refer: https://godoc.org/github.com/astaxie/beego#Head func (n *Namespace) Head(rootpath string, f FilterFunc) *Namespace { n.handlers.Head(rootpath, f) return n } -// same as beego.Options +// Options same as beego.Options // refer: https://godoc.org/github.com/astaxie/beego#Options func (n *Namespace) Options(rootpath string, f FilterFunc) *Namespace { n.handlers.Options(rootpath, f) return n } -// same as beego.Patch +// Patch same as beego.Patch // refer: https://godoc.org/github.com/astaxie/beego#Patch func (n *Namespace) Patch(rootpath string, f FilterFunc) *Namespace { n.handlers.Patch(rootpath, f) return n } -// same as beego.Any +// Any same as beego.Any // refer: https://godoc.org/github.com/astaxie/beego#Any func (n *Namespace) Any(rootpath string, f FilterFunc) *Namespace { n.handlers.Any(rootpath, f) return n } -// same as beego.Handler +// Handler same as beego.Handler // refer: https://godoc.org/github.com/astaxie/beego#Handler func (n *Namespace) Handler(rootpath string, h http.Handler) *Namespace { n.handlers.Handler(rootpath, h) return n } -// add include class +// Include add include class // refer: https://godoc.org/github.com/astaxie/beego#Include func (n *Namespace) Include(cList ...ControllerInterface) *Namespace { n.handlers.Include(cList...) return n } -// nest Namespace +// Namespace add nest Namespace // usage: //ns := beego.NewNamespace(“/v1”). //Namespace( @@ -230,7 +231,7 @@ func (n *Namespace) Namespace(ns ...*Namespace) *Namespace { return n } -// register Namespace into beego.Handler +// AddNamespace register Namespace into beego.Handler // support multi Namespace func AddNamespace(nl ...*Namespace) { for _, n := range nl { @@ -275,113 +276,113 @@ func addPrefix(t *Tree, prefix string) { } -// Namespace Condition -func NSCond(cond namespaceCond) innerNamespace { +// NSCond is Namespace Condition +func NSCond(cond namespaceCond) LinkNamespace { return func(ns *Namespace) { ns.Cond(cond) } } -// Namespace BeforeRouter filter -func NSBefore(filiterList ...FilterFunc) innerNamespace { +// NSBefore Namespace BeforeRouter filter +func NSBefore(filiterList ...FilterFunc) LinkNamespace { return func(ns *Namespace) { ns.Filter("before", filiterList...) } } -// Namespace FinishRouter filter -func NSAfter(filiterList ...FilterFunc) innerNamespace { +// NSAfter add Namespace FinishRouter filter +func NSAfter(filiterList ...FilterFunc) LinkNamespace { return func(ns *Namespace) { ns.Filter("after", filiterList...) } } -// Namespace Include ControllerInterface -func NSInclude(cList ...ControllerInterface) innerNamespace { +// NSInclude Namespace Include ControllerInterface +func NSInclude(cList ...ControllerInterface) LinkNamespace { return func(ns *Namespace) { ns.Include(cList...) } } -// Namespace Router -func NSRouter(rootpath string, c ControllerInterface, mappingMethods ...string) innerNamespace { +// NSRouter call Namespace Router +func NSRouter(rootpath string, c ControllerInterface, mappingMethods ...string) LinkNamespace { return func(ns *Namespace) { ns.Router(rootpath, c, mappingMethods...) } } -// Namespace Get -func NSGet(rootpath string, f FilterFunc) innerNamespace { +// NSGet call Namespace Get +func NSGet(rootpath string, f FilterFunc) LinkNamespace { return func(ns *Namespace) { ns.Get(rootpath, f) } } -// Namespace Post -func NSPost(rootpath string, f FilterFunc) innerNamespace { +// NSPost call Namespace Post +func NSPost(rootpath string, f FilterFunc) LinkNamespace { return func(ns *Namespace) { ns.Post(rootpath, f) } } -// Namespace Head -func NSHead(rootpath string, f FilterFunc) innerNamespace { +// NSHead call Namespace Head +func NSHead(rootpath string, f FilterFunc) LinkNamespace { return func(ns *Namespace) { ns.Head(rootpath, f) } } -// Namespace Put -func NSPut(rootpath string, f FilterFunc) innerNamespace { +// NSPut call Namespace Put +func NSPut(rootpath string, f FilterFunc) LinkNamespace { return func(ns *Namespace) { ns.Put(rootpath, f) } } -// Namespace Delete -func NSDelete(rootpath string, f FilterFunc) innerNamespace { +// NSDelete call Namespace Delete +func NSDelete(rootpath string, f FilterFunc) LinkNamespace { return func(ns *Namespace) { ns.Delete(rootpath, f) } } -// Namespace Any -func NSAny(rootpath string, f FilterFunc) innerNamespace { +// NSAny call Namespace Any +func NSAny(rootpath string, f FilterFunc) LinkNamespace { return func(ns *Namespace) { ns.Any(rootpath, f) } } -// Namespace Options -func NSOptions(rootpath string, f FilterFunc) innerNamespace { +// NSOptions call Namespace Options +func NSOptions(rootpath string, f FilterFunc) LinkNamespace { return func(ns *Namespace) { ns.Options(rootpath, f) } } -// Namespace Patch -func NSPatch(rootpath string, f FilterFunc) innerNamespace { +// NSPatch call Namespace Patch +func NSPatch(rootpath string, f FilterFunc) LinkNamespace { return func(ns *Namespace) { ns.Patch(rootpath, f) } } -//Namespace AutoRouter -func NSAutoRouter(c ControllerInterface) innerNamespace { +// NSAutoRouter call Namespace AutoRouter +func NSAutoRouter(c ControllerInterface) LinkNamespace { return func(ns *Namespace) { ns.AutoRouter(c) } } -// Namespace AutoPrefix -func NSAutoPrefix(prefix string, c ControllerInterface) innerNamespace { +// NSAutoPrefix call Namespace AutoPrefix +func NSAutoPrefix(prefix string, c ControllerInterface) LinkNamespace { return func(ns *Namespace) { ns.AutoPrefix(prefix, c) } } -// Namespace add sub Namespace -func NSNamespace(prefix string, params ...innerNamespace) innerNamespace { +// NSNamespace add sub Namespace +func NSNamespace(prefix string, params ...LinkNamespace) LinkNamespace { return func(ns *Namespace) { n := NewNamespace(prefix, params...) ns.Namespace(n) diff --git a/router.go b/router.go index 6fbf90ea..dc4ddb0f 100644 --- a/router.go +++ b/router.go @@ -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 EnableXSRF { - execController.XsrfToken() + execController.XSRFToken() if r.Method == "POST" || r.Method == "DELETE" || r.Method == "PUT" || (r.Method == "POST" && (context.Input.Query("_method") == "DELETE" || context.Input.Query("_method") == "PUT")) { - execController.CheckXsrfCookie() + execController.CheckXSRFCookie() } } diff --git a/router_test.go b/router_test.go index 005f32d6..093a1fad 100644 --- a/router_test.go +++ b/router_test.go @@ -53,7 +53,7 @@ func (tc *TestController) Myext() { } func (tc *TestController) GetUrl() { - tc.Ctx.Output.Body([]byte(tc.UrlFor(".Myext"))) + tc.Ctx.Output.Body([]byte(tc.URLFor(".Myext"))) } func (t *TestController) GetParams() { @@ -76,7 +76,7 @@ type JsonController struct { func (this *JsonController) Prepare() { this.Data["json"] = "prepare" - this.ServeJson(true) + this.ServeJSON(true) } func (this *JsonController) Get() {