mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 07:50:54 +00:00
golint all the files
This commit is contained in:
parent
da36d1d0e7
commit
f925bb9058
7
cache/cache.go
vendored
7
cache/cache.go
vendored
@ -67,14 +67,15 @@ type Cache interface {
|
|||||||
StartAndGC(config string) error
|
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.
|
// Register makes a cache adapter available by the adapter name.
|
||||||
// If Register is called twice with the same name or if driver is nil,
|
// If Register is called twice with the same name or if driver is nil,
|
||||||
// it panics.
|
// it panics.
|
||||||
func Register(name string, adapter CacheInstance) {
|
func Register(name string, adapter Instance) {
|
||||||
if adapter == nil {
|
if adapter == nil {
|
||||||
panic("cache: Register adapter is nil")
|
panic("cache: Register adapter is nil")
|
||||||
}
|
}
|
||||||
|
8
cache/file.go
vendored
8
cache/file.go
vendored
@ -39,10 +39,10 @@ type FileCacheItem struct {
|
|||||||
|
|
||||||
// FileCache Config
|
// FileCache Config
|
||||||
var (
|
var (
|
||||||
FileCachePath = "cache" // cache directory
|
FileCachePath = "cache" // cache directory
|
||||||
FileCacheFileSuffix = ".bin" // cache file suffix
|
FileCacheFileSuffix = ".bin" // cache file suffix
|
||||||
FileCacheDirectoryLevel = 2 // cache file deep level if auto generated cache files.
|
FileCacheDirectoryLevel = 2 // cache file deep level if auto generated cache files.
|
||||||
FileCacheEmbedExpiry time.Duration = 0 // cache expire time, default is no expire forever.
|
FileCacheEmbedExpiry time.Duration // cache expire time, default is no expire forever.
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileCache is cache adapter for file storage.
|
// FileCache is cache adapter for file storage.
|
||||||
|
11
config.go
11
config.go
@ -25,7 +25,8 @@ import (
|
|||||||
"github.com/astaxie/beego/utils"
|
"github.com/astaxie/beego/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BeegoConfig struct {
|
// BeegoConfig is the main struct for BConfig
|
||||||
|
type Config struct {
|
||||||
AppName string //Application name
|
AppName string //Application name
|
||||||
RunMode string //Running Mode: dev | prod
|
RunMode string //Running Mode: dev | prod
|
||||||
RouterCaseSensitive bool
|
RouterCaseSensitive bool
|
||||||
@ -40,6 +41,7 @@ type BeegoConfig struct {
|
|||||||
Log LogConfig
|
Log LogConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Listen holds for http and https related config
|
||||||
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
|
||||||
@ -59,6 +61,7 @@ type Listen struct {
|
|||||||
EnableStdIo bool // EnableStdIo works with EnableFcgi Use FCGI via standard I/O
|
EnableStdIo bool // EnableStdIo works with EnableFcgi Use FCGI via standard I/O
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebConfig holds web related config
|
||||||
type WebConfig struct {
|
type WebConfig struct {
|
||||||
AutoRender bool
|
AutoRender bool
|
||||||
EnableDocs bool
|
EnableDocs bool
|
||||||
@ -76,6 +79,7 @@ type WebConfig struct {
|
|||||||
Session SessionConfig
|
Session SessionConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SessionConfig holds session related config
|
||||||
type SessionConfig struct {
|
type SessionConfig struct {
|
||||||
SessionOn bool
|
SessionOn bool
|
||||||
SessionProvider string
|
SessionProvider string
|
||||||
@ -87,6 +91,7 @@ type SessionConfig struct {
|
|||||||
SessionDomain string
|
SessionDomain string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LogConfig holds Log related config
|
||||||
type LogConfig struct {
|
type LogConfig struct {
|
||||||
AccessLogs bool
|
AccessLogs bool
|
||||||
FileLineNum bool
|
FileLineNum bool
|
||||||
@ -95,7 +100,7 @@ type LogConfig struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// BConfig is the default config for Application
|
// BConfig is the default config for Application
|
||||||
BConfig *BeegoConfig
|
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
|
||||||
AppConfig *beegoAppConfig
|
AppConfig *beegoAppConfig
|
||||||
// AppConfigPath is the path to the config files
|
// AppConfigPath is the path to the config files
|
||||||
@ -109,7 +114,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
BConfig = &BeegoConfig{
|
BConfig = &Config{
|
||||||
AppName: "beego",
|
AppName: "beego",
|
||||||
RunMode: DEV,
|
RunMode: DEV,
|
||||||
RouterCaseSensitive: true,
|
RouterCaseSensitive: true,
|
||||||
|
@ -192,7 +192,6 @@ func parseEncoding(r *http.Request) string {
|
|||||||
}
|
}
|
||||||
if cf, ok := encoderMap[lastQ.name]; ok {
|
if cf, ok := encoderMap[lastQ.name]; ok {
|
||||||
return cf.name
|
return cf.name
|
||||||
} else {
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -393,10 +393,8 @@ func (c *Controller) GetStrings(key string, def ...[]string) []string {
|
|||||||
|
|
||||||
if f := c.Input(); f == nil {
|
if f := c.Input(); f == nil {
|
||||||
return defv
|
return defv
|
||||||
} else {
|
} else if vs := f[key]; len(vs) > 0 {
|
||||||
if vs := f[key]; len(vs) > 0 {
|
return vs
|
||||||
return vs
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return defv
|
return defv
|
||||||
|
2
error.go
2
error.go
@ -204,7 +204,7 @@ type errorInfo struct {
|
|||||||
errorType int
|
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)
|
// there is 10 kinds default error(40x and 50x)
|
||||||
var ErrorMaps = make(map[string]*errorInfo, 10)
|
var ErrorMaps = make(map[string]*errorInfo, 10)
|
||||||
|
|
||||||
|
@ -42,18 +42,18 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
|
|||||||
dbase := orm.alias.DbBaser
|
dbase := orm.alias.DbBaser
|
||||||
|
|
||||||
var models []interface{}
|
var models []interface{}
|
||||||
var other_values []interface{}
|
var otherValues []interface{}
|
||||||
var other_names []string
|
var otherNames []string
|
||||||
|
|
||||||
for _, colname := range mi.fields.dbcols {
|
for _, colname := range mi.fields.dbcols {
|
||||||
if colname != mfi.column && colname != rfi.column && colname != fi.mi.fields.pk.column &&
|
if colname != mfi.column && colname != rfi.column && colname != fi.mi.fields.pk.column &&
|
||||||
mi.fields.columns[colname] != mi.fields.pk {
|
mi.fields.columns[colname] != mi.fields.pk {
|
||||||
other_names = append(other_names, colname)
|
otherNames = append(otherNames, colname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, md := range mds {
|
for i, md := range mds {
|
||||||
if reflect.Indirect(reflect.ValueOf(md)).Kind() != reflect.Struct && i > 0 {
|
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:]...)
|
mds = append(mds[:i], mds[i+1:]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,8 +94,8 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
|
|||||||
values = append(values, v1, v2)
|
values = append(values, v1, v2)
|
||||||
|
|
||||||
}
|
}
|
||||||
names = append(names, other_names...)
|
names = append(names, otherNames...)
|
||||||
values = append(values, other_values...)
|
values = append(values, otherValues...)
|
||||||
return dbase.InsertValue(orm.db, mi, true, names, values)
|
return dbase.InsertValue(orm.db, mi, true, names, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
router.go
12
router.go
@ -504,12 +504,12 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
|
|||||||
if find {
|
if find {
|
||||||
if l.regexps == nil {
|
if l.regexps == nil {
|
||||||
if len(l.wildcards) == 0 {
|
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 len(l.wildcards) == 1 {
|
||||||
if v, ok := params[l.wildcards[0]]; ok {
|
if v, ok := params[l.wildcards[0]]; ok {
|
||||||
delete(params, l.wildcards[0])
|
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, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
@ -518,7 +518,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
|
|||||||
if e, isok := params[":ext"]; isok {
|
if e, isok := params[":ext"]; isok {
|
||||||
delete(params, ":path")
|
delete(params, ":path")
|
||||||
delete(params, ":ext")
|
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 false, ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true, url + toUrl(params)
|
return true, url + toURL(params)
|
||||||
}
|
}
|
||||||
var i int
|
var i int
|
||||||
var startreg bool
|
var startreg bool
|
||||||
@ -566,7 +566,7 @@ func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName strin
|
|||||||
for _, p := range ps {
|
for _, p := range ps {
|
||||||
url = strings.Replace(url, urlPlaceholder, p, 1)
|
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 {
|
if len(params) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ import (
|
|||||||
|
|
||||||
var redispder = &Provider{}
|
var redispder = &Provider{}
|
||||||
|
|
||||||
// redis max pool size
|
// MaxPoolSize redis max pool size
|
||||||
var MaxPoolSize = 100
|
var MaxPoolSize = 100
|
||||||
|
|
||||||
// SessionStore redis session store
|
// SessionStore redis session store
|
||||||
|
@ -16,6 +16,7 @@ package beego
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -23,15 +24,12 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/astaxie/beego/context"
|
"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) {
|
func serverStaticRouter(ctx *context.Context) {
|
||||||
if ctx.Input.Method() != "GET" && ctx.Input.Method() != "HEAD" {
|
if ctx.Input.Method() != "GET" && ctx.Input.Method() != "HEAD" {
|
||||||
@ -39,7 +37,7 @@ func serverStaticRouter(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
forbidden, filePath, fileInfo, err := lookupFile(ctx)
|
forbidden, filePath, fileInfo, err := lookupFile(ctx)
|
||||||
if err == notStaticRequestErr {
|
if err == errNotStaticRequest {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +173,7 @@ func searchFile(ctx *context.Context) (string, os.FileInfo, error) {
|
|||||||
return filePath, fi, err
|
return filePath, fi, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", nil, notStaticRequestErr
|
return "", nil, errNotStaticRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookupFile find the file to serve
|
// lookupFile find the file to serve
|
||||||
|
@ -50,7 +50,7 @@ func init() {
|
|||||||
beegoTplFuncMap["renderform"] = RenderForm
|
beegoTplFuncMap["renderform"] = RenderForm
|
||||||
beegoTplFuncMap["assets_js"] = AssetsJs
|
beegoTplFuncMap["assets_js"] = AssetsJs
|
||||||
beegoTplFuncMap["assets_css"] = AssetsCSS
|
beegoTplFuncMap["assets_css"] = AssetsCSS
|
||||||
beegoTplFuncMap["config"] = Config
|
beegoTplFuncMap["config"] = GetConfig
|
||||||
beegoTplFuncMap["map_get"] = MapGet
|
beegoTplFuncMap["map_get"] = MapGet
|
||||||
|
|
||||||
// go1.2 added template funcs
|
// go1.2 added template funcs
|
||||||
|
@ -149,8 +149,8 @@ func NotNil(a interface{}) (isNil bool) {
|
|||||||
return CompareNot(a, nil)
|
return CompareNot(a, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config get the Appconfig
|
// GetConfig get the Appconfig
|
||||||
func Config(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":
|
||||||
value = AppConfig.String(key)
|
value = AppConfig.String(key)
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
// more docs: http://beego.me/docs/module/toolbox.md
|
// more docs: http://beego.me/docs/module/toolbox.md
|
||||||
package toolbox
|
package toolbox
|
||||||
|
|
||||||
// health checker map
|
// AdminCheckList holds health checker map
|
||||||
var AdminCheckList map[string]HealthChecker
|
var AdminCheckList map[string]HealthChecker
|
||||||
|
|
||||||
// HealthChecker health checker interface
|
// HealthChecker health checker interface
|
||||||
|
@ -133,7 +133,7 @@ func (m *URLMap) GetMapData() []map[string]interface{} {
|
|||||||
return resultLists
|
return resultLists
|
||||||
}
|
}
|
||||||
|
|
||||||
// global statistics data map
|
// StatisticsMap hosld global statistics data map
|
||||||
var StatisticsMap *URLMap
|
var StatisticsMap *URLMap
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -56,9 +56,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CustomFunc is for custom validate function
|
||||||
type CustomFunc func(v *Validation, obj interface{}, key string)
|
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:
|
// The name can not be:
|
||||||
// Clear
|
// Clear
|
||||||
// HasErrors
|
// HasErrors
|
||||||
|
@ -46,7 +46,7 @@ var MessageTmpls = map[string]string{
|
|||||||
"ZipCode": "Must be valid zipcode",
|
"ZipCode": "Must be valid zipcode",
|
||||||
}
|
}
|
||||||
|
|
||||||
// set default messages
|
// SetDefaultMessage set default messages
|
||||||
// if not set, the default messages are
|
// if not set, the default messages are
|
||||||
// "Required": "Can not be empty",
|
// "Required": "Can not be empty",
|
||||||
// "Min": "Minimum is %d",
|
// "Min": "Minimum is %d",
|
||||||
|
Loading…
Reference in New Issue
Block a user