mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 18:40:55 +00:00
make the code mode readable
golint all the files
This commit is contained in:
commit
eb0bc084ec
7
cache/cache.go
vendored
7
cache/cache.go
vendored
@ -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")
|
||||
}
|
||||
|
8
cache/file.go
vendored
8
cache/file.go
vendored
@ -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.
|
||||
|
11
config.go
11
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,
|
||||
|
@ -192,7 +192,6 @@ func parseEncoding(r *http.Request) string {
|
||||
}
|
||||
if cf, ok := encoderMap[lastQ.name]; ok {
|
||||
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 {
|
||||
return defv
|
||||
} else {
|
||||
if vs := f[key]; len(vs) > 0 {
|
||||
return vs
|
||||
}
|
||||
} else if vs := f[key]; len(vs) > 0 {
|
||||
return vs
|
||||
}
|
||||
|
||||
return defv
|
||||
|
2
error.go
2
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)
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
12
router.go
12
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 ""
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ import (
|
||||
|
||||
var redispder = &Provider{}
|
||||
|
||||
// redis max pool size
|
||||
// MaxPoolSize redis max pool size
|
||||
var MaxPoolSize = 100
|
||||
|
||||
// SessionStore redis session store
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
@ -103,8 +103,8 @@ func (e *Email) Bytes() ([]byte, error) {
|
||||
}
|
||||
|
||||
e.Headers.Set("Content-Type", fmt.Sprintf("multipart/mixed;\r\n boundary=%s\r\n", w.Boundary()))
|
||||
fmt.Fprintf(w, "%s:", "Content-Type")
|
||||
fmt.Fprintf(w, " %s\r\n", fmt.Sprintf("multipart/mixed;\r\n boundary=%s\r\n", w.Boundary()))
|
||||
fmt.Fprintf(buff, "%s:", "Content-Type")
|
||||
fmt.Fprintf(buff, " %s\r\n", fmt.Sprintf("multipart/mixed;\r\n boundary=%s\r\n", w.Boundary()))
|
||||
|
||||
// Start the multipart/mixed part
|
||||
fmt.Fprintf(buff, "--%s\r\n", w.Boundary())
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user