From f925bb90589de3f5522b0f23060a34aefced0af5 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 18 Jan 2016 00:18:21 +0800 Subject: [PATCH] golint all the files --- cache/cache.go | 7 ++++--- cache/file.go | 8 ++++---- config.go | 11 ++++++++--- context/acceptencoder.go | 3 +-- controller.go | 6 ++---- error.go | 2 +- orm/orm_querym2m.go | 12 ++++++------ router.go | 12 ++++++------ session/redis/sess_redis.go | 2 +- staticfile.go | 10 ++++------ template.go | 2 +- templatefunc.go | 4 ++-- toolbox/healthcheck.go | 2 +- toolbox/statistics.go | 2 +- validation/util.go | 3 ++- validation/validators.go | 2 +- 16 files changed, 45 insertions(+), 43 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 2008402e..f7158741 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -67,14 +67,15 @@ type Cache interface { StartAndGC(config string) error } -type CacheInstance func() Cache +// Instance is a function create a new Cache Instance +type Instance func() Cache -var adapters = make(map[string]CacheInstance) +var adapters = make(map[string]Instance) // Register makes a cache adapter available by the adapter name. // If Register is called twice with the same name or if driver is nil, // it panics. -func Register(name string, adapter CacheInstance) { +func Register(name string, adapter Instance) { if adapter == nil { panic("cache: Register adapter is nil") } diff --git a/cache/file.go b/cache/file.go index e2ba70e3..4b030980 100644 --- a/cache/file.go +++ b/cache/file.go @@ -39,10 +39,10 @@ type FileCacheItem struct { // FileCache Config var ( - FileCachePath = "cache" // cache directory - FileCacheFileSuffix = ".bin" // cache file suffix - FileCacheDirectoryLevel = 2 // cache file deep level if auto generated cache files. - FileCacheEmbedExpiry time.Duration = 0 // cache expire time, default is no expire forever. + FileCachePath = "cache" // cache directory + FileCacheFileSuffix = ".bin" // cache file suffix + FileCacheDirectoryLevel = 2 // cache file deep level if auto generated cache files. + FileCacheEmbedExpiry time.Duration // cache expire time, default is no expire forever. ) // FileCache is cache adapter for file storage. diff --git a/config.go b/config.go index cffb7c2b..bc5ac640 100644 --- a/config.go +++ b/config.go @@ -25,7 +25,8 @@ import ( "github.com/astaxie/beego/utils" ) -type BeegoConfig struct { +// BeegoConfig is the main struct for BConfig +type Config struct { AppName string //Application name RunMode string //Running Mode: dev | prod RouterCaseSensitive bool @@ -40,6 +41,7 @@ type BeegoConfig struct { Log LogConfig } +// Listen holds for http and https related config type Listen struct { Graceful bool // Graceful means use graceful module to start the server ServerTimeOut int64 @@ -59,6 +61,7 @@ type Listen struct { EnableStdIo bool // EnableStdIo works with EnableFcgi Use FCGI via standard I/O } +// WebConfig holds web related config type WebConfig struct { AutoRender bool EnableDocs bool @@ -76,6 +79,7 @@ type WebConfig struct { Session SessionConfig } +// SessionConfig holds session related config type SessionConfig struct { SessionOn bool SessionProvider string @@ -87,6 +91,7 @@ type SessionConfig struct { SessionDomain string } +// LogConfig holds Log related config type LogConfig struct { AccessLogs bool FileLineNum bool @@ -95,7 +100,7 @@ type LogConfig struct { var ( // BConfig is the default config for Application - BConfig *BeegoConfig + BConfig *Config // AppConfig is the instance of Config, store the config information from file AppConfig *beegoAppConfig // AppConfigPath is the path to the config files @@ -109,7 +114,7 @@ var ( ) func init() { - BConfig = &BeegoConfig{ + BConfig = &Config{ AppName: "beego", RunMode: DEV, RouterCaseSensitive: true, diff --git a/context/acceptencoder.go b/context/acceptencoder.go index 07c5cb0b..033d9ca8 100644 --- a/context/acceptencoder.go +++ b/context/acceptencoder.go @@ -192,7 +192,6 @@ func parseEncoding(r *http.Request) string { } if cf, ok := encoderMap[lastQ.name]; ok { return cf.name - } else { - return "" } + return "" } diff --git a/controller.go b/controller.go index ab261a56..624e574a 100644 --- a/controller.go +++ b/controller.go @@ -393,10 +393,8 @@ func (c *Controller) GetStrings(key string, def ...[]string) []string { if f := c.Input(); f == nil { return defv - } else { - if vs := f[key]; len(vs) > 0 { - return vs - } + } else if vs := f[key]; len(vs) > 0 { + return vs } return defv diff --git a/error.go b/error.go index af57b7c7..94151dd8 100644 --- a/error.go +++ b/error.go @@ -204,7 +204,7 @@ type errorInfo struct { errorType int } -// 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) var ErrorMaps = make(map[string]*errorInfo, 10) diff --git a/orm/orm_querym2m.go b/orm/orm_querym2m.go index 60c77cdf..b220bda6 100644 --- a/orm/orm_querym2m.go +++ b/orm/orm_querym2m.go @@ -42,18 +42,18 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) { dbase := orm.alias.DbBaser var models []interface{} - var other_values []interface{} - var other_names []string + var otherValues []interface{} + var otherNames []string for _, colname := range mi.fields.dbcols { if colname != mfi.column && colname != rfi.column && colname != fi.mi.fields.pk.column && mi.fields.columns[colname] != mi.fields.pk { - other_names = append(other_names, colname) + otherNames = append(otherNames, colname) } } for i, md := range mds { if reflect.Indirect(reflect.ValueOf(md)).Kind() != reflect.Struct && i > 0 { - other_values = append(other_values, md) + otherValues = append(otherValues, md) mds = append(mds[:i], mds[i+1:]...) } } @@ -94,8 +94,8 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) { values = append(values, v1, v2) } - names = append(names, other_names...) - values = append(values, other_values...) + names = append(names, otherNames...) + values = append(values, otherValues...) return dbase.InsertValue(orm.db, mi, true, names, values) } diff --git a/router.go b/router.go index 9d8cd2e6..b3935c27 100644 --- a/router.go +++ b/router.go @@ -504,12 +504,12 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin if find { if l.regexps == nil { if len(l.wildcards) == 0 { - return true, strings.Replace(url, "/"+urlPlaceholder, "", 1) + toUrl(params) + return true, strings.Replace(url, "/"+urlPlaceholder, "", 1) + toURL(params) } if len(l.wildcards) == 1 { if v, ok := params[l.wildcards[0]]; ok { delete(params, l.wildcards[0]) - return true, strings.Replace(url, urlPlaceholder, v, 1) + toUrl(params) + return true, strings.Replace(url, urlPlaceholder, v, 1) + toURL(params) } return false, "" } @@ -518,7 +518,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin if e, isok := params[":ext"]; isok { delete(params, ":path") delete(params, ":ext") - return true, strings.Replace(url, urlPlaceholder, p+"."+e, -1) + toUrl(params) + return true, strings.Replace(url, urlPlaceholder, p+"."+e, -1) + toURL(params) } } } @@ -539,7 +539,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin return false, "" } } - return true, url + toUrl(params) + return true, url + toURL(params) } var i int var startreg bool @@ -566,7 +566,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin for _, p := range ps { url = strings.Replace(url, urlPlaceholder, p, 1) } - return true, url + toUrl(params) + return true, url + toURL(params) } } } @@ -864,7 +864,7 @@ func (p *ControllerRegister) recoverPanic(context *beecontext.Context) { } } -func toUrl(params map[string]string) string { +func toURL(params map[string]string) string { if len(params) == 0 { return "" } diff --git a/session/redis/sess_redis.go b/session/redis/sess_redis.go index 99a672d5..5107a8d1 100644 --- a/session/redis/sess_redis.go +++ b/session/redis/sess_redis.go @@ -45,7 +45,7 @@ import ( var redispder = &Provider{} -// redis max pool size +// MaxPoolSize redis max pool size var MaxPoolSize = 100 // SessionStore redis session store diff --git a/staticfile.go b/staticfile.go index f9f3dc3e..9534ce91 100644 --- a/staticfile.go +++ b/staticfile.go @@ -16,6 +16,7 @@ package beego import ( "bytes" + "errors" "net/http" "os" "path" @@ -23,15 +24,12 @@ import ( "strconv" "strings" "sync" - - "errors" - "time" "github.com/astaxie/beego/context" ) -var notStaticRequestErr = errors.New("request not a static file request") +var errNotStaticRequest = errors.New("request not a static file request") func serverStaticRouter(ctx *context.Context) { if ctx.Input.Method() != "GET" && ctx.Input.Method() != "HEAD" { @@ -39,7 +37,7 @@ func serverStaticRouter(ctx *context.Context) { } forbidden, filePath, fileInfo, err := lookupFile(ctx) - if err == notStaticRequestErr { + if err == errNotStaticRequest { return } @@ -175,7 +173,7 @@ func searchFile(ctx *context.Context) (string, os.FileInfo, error) { return filePath, fi, err } } - return "", nil, notStaticRequestErr + return "", nil, errNotStaticRequest } // lookupFile find the file to serve diff --git a/template.go b/template.go index 0ff2eea0..363c6754 100644 --- a/template.go +++ b/template.go @@ -50,7 +50,7 @@ func init() { beegoTplFuncMap["renderform"] = RenderForm beegoTplFuncMap["assets_js"] = AssetsJs beegoTplFuncMap["assets_css"] = AssetsCSS - beegoTplFuncMap["config"] = Config + beegoTplFuncMap["config"] = GetConfig beegoTplFuncMap["map_get"] = MapGet // go1.2 added template funcs diff --git a/templatefunc.go b/templatefunc.go index bc265321..8558733f 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -149,8 +149,8 @@ func NotNil(a interface{}) (isNil bool) { return CompareNot(a, nil) } -// Config get the Appconfig -func Config(returnType, key string, defaultVal interface{}) (value interface{}, err error) { +// GetConfig get the Appconfig +func GetConfig(returnType, key string, defaultVal interface{}) (value interface{}, err error) { switch returnType { case "String": value = AppConfig.String(key) diff --git a/toolbox/healthcheck.go b/toolbox/healthcheck.go index 46251eda..e3544b3a 100644 --- a/toolbox/healthcheck.go +++ b/toolbox/healthcheck.go @@ -30,7 +30,7 @@ // more docs: http://beego.me/docs/module/toolbox.md package toolbox -// health checker map +// AdminCheckList holds health checker map var AdminCheckList map[string]HealthChecker // HealthChecker health checker interface diff --git a/toolbox/statistics.go b/toolbox/statistics.go index 59c0ba0f..32eb7e23 100644 --- a/toolbox/statistics.go +++ b/toolbox/statistics.go @@ -133,7 +133,7 @@ func (m *URLMap) GetMapData() []map[string]interface{} { return resultLists } -// global statistics data map +// StatisticsMap hosld global statistics data map var StatisticsMap *URLMap func init() { diff --git a/validation/util.go b/validation/util.go index 7c3fd20c..9e7460a6 100644 --- a/validation/util.go +++ b/validation/util.go @@ -56,9 +56,10 @@ func init() { } } +// CustomFunc is for custom validate function type CustomFunc func(v *Validation, obj interface{}, key string) -// Add a custom function to validation +// AddCustomFunc Add a custom function to validation // The name can not be: // Clear // HasErrors diff --git a/validation/validators.go b/validation/validators.go index 9d9df467..ebff2191 100644 --- a/validation/validators.go +++ b/validation/validators.go @@ -46,7 +46,7 @@ var MessageTmpls = map[string]string{ "ZipCode": "Must be valid zipcode", } -// set default messages +// SetDefaultMessage set default messages // if not set, the default messages are // "Required": "Can not be empty", // "Min": "Minimum is %d",