mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 03:40:55 +00:00
list the config to map
This commit is contained in:
parent
203ab3eba8
commit
423f2dad35
74
admin.go
74
admin.go
@ -23,6 +23,8 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/astaxie/beego/grace"
|
"github.com/astaxie/beego/grace"
|
||||||
"github.com/astaxie/beego/logs"
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/astaxie/beego/toolbox"
|
"github.com/astaxie/beego/toolbox"
|
||||||
@ -91,57 +93,9 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
|||||||
switch command {
|
switch command {
|
||||||
case "conf":
|
case "conf":
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
|
list("BConfig", BConfig, m)
|
||||||
m["AppConfigPath"] = appConfigPath
|
m["AppConfigPath"] = appConfigPath
|
||||||
m["AppConfigProvider"] = appConfigProvider
|
m["AppConfigProvider"] = appConfigProvider
|
||||||
m["BConfig.AppName"] = BConfig.AppName
|
|
||||||
m["BConfig.RunMode"] = BConfig.RunMode
|
|
||||||
m["BConfig.RouterCaseSensitive"] = BConfig.RouterCaseSensitive
|
|
||||||
m["BConfig.ServerName"] = BConfig.ServerName
|
|
||||||
m["BConfig.RecoverPanic"] = BConfig.RecoverPanic
|
|
||||||
m["BConfig.CopyRequestBody"] = BConfig.CopyRequestBody
|
|
||||||
m["BConfig.EnableGzip"] = BConfig.EnableGzip
|
|
||||||
m["BConfig.MaxMemory"] = BConfig.MaxMemory
|
|
||||||
m["BConfig.EnableErrorsShow"] = BConfig.EnableErrorsShow
|
|
||||||
m["BConfig.Listen.Graceful"] = BConfig.Listen.Graceful
|
|
||||||
m["BConfig.Listen.ServerTimeOut"] = BConfig.Listen.ServerTimeOut
|
|
||||||
m["BConfig.Listen.ListenTCP4"] = BConfig.Listen.ListenTCP4
|
|
||||||
m["BConfig.Listen.EnableHTTP"] = BConfig.Listen.EnableHTTP
|
|
||||||
m["BConfig.Listen.HTTPAddr"] = BConfig.Listen.HTTPAddr
|
|
||||||
m["BConfig.Listen.HTTPPort"] = BConfig.Listen.HTTPPort
|
|
||||||
m["BConfig.Listen.EnableHTTPS"] = BConfig.Listen.EnableHTTPS
|
|
||||||
m["BConfig.Listen.HTTPSAddr"] = BConfig.Listen.HTTPSAddr
|
|
||||||
m["BConfig.Listen.HTTPSPort"] = BConfig.Listen.HTTPSPort
|
|
||||||
m["BConfig.Listen.HTTPSCertFile"] = BConfig.Listen.HTTPSCertFile
|
|
||||||
m["BConfig.Listen.HTTPSKeyFile"] = BConfig.Listen.HTTPSKeyFile
|
|
||||||
m["BConfig.Listen.EnableAdmin"] = BConfig.Listen.EnableAdmin
|
|
||||||
m["BConfig.Listen.AdminAddr"] = BConfig.Listen.AdminAddr
|
|
||||||
m["BConfig.Listen.AdminPort"] = BConfig.Listen.AdminPort
|
|
||||||
m["BConfig.Listen.EnableFcgi"] = BConfig.Listen.EnableFcgi
|
|
||||||
m["BConfig.Listen.EnableStdIo"] = BConfig.Listen.EnableStdIo
|
|
||||||
m["BConfig.WebConfig.AutoRender"] = BConfig.WebConfig.AutoRender
|
|
||||||
m["BConfig.WebConfig.EnableDocs"] = BConfig.WebConfig.EnableDocs
|
|
||||||
m["BConfig.WebConfig.FlashName"] = BConfig.WebConfig.FlashName
|
|
||||||
m["BConfig.WebConfig.FlashSeparator"] = BConfig.WebConfig.FlashSeparator
|
|
||||||
m["BConfig.WebConfig.DirectoryIndex"] = BConfig.WebConfig.DirectoryIndex
|
|
||||||
m["BConfig.WebConfig.StaticDir"] = BConfig.WebConfig.StaticDir
|
|
||||||
m["BConfig.WebConfig.StaticExtensionsToGzip"] = BConfig.WebConfig.StaticExtensionsToGzip
|
|
||||||
m["BConfig.WebConfig.TemplateLeft"] = BConfig.WebConfig.TemplateLeft
|
|
||||||
m["BConfig.WebConfig.TemplateRight"] = BConfig.WebConfig.TemplateRight
|
|
||||||
m["BConfig.WebConfig.ViewsPath"] = BConfig.WebConfig.ViewsPath
|
|
||||||
m["BConfig.WebConfig.EnableXSRF"] = BConfig.WebConfig.EnableXSRF
|
|
||||||
m["BConfig.WebConfig.XSRFKEY"] = BConfig.WebConfig.XSRFKey
|
|
||||||
m["BConfig.WebConfig.XSRFExpire"] = BConfig.WebConfig.XSRFExpire
|
|
||||||
m["BConfig.WebConfig.Session.SessionOn"] = BConfig.WebConfig.Session.SessionOn
|
|
||||||
m["BConfig.WebConfig.Session.SessionProvider"] = BConfig.WebConfig.Session.SessionProvider
|
|
||||||
m["BConfig.WebConfig.Session.SessionName"] = BConfig.WebConfig.Session.SessionName
|
|
||||||
m["BConfig.WebConfig.Session.SessionGCMaxLifetime"] = BConfig.WebConfig.Session.SessionGCMaxLifetime
|
|
||||||
m["BConfig.WebConfig.Session.SessionProviderConfig"] = BConfig.WebConfig.Session.SessionProviderConfig
|
|
||||||
m["BConfig.WebConfig.Session.SessionCookieLifeTime"] = BConfig.WebConfig.Session.SessionCookieLifeTime
|
|
||||||
m["BConfig.WebConfig.Session.SessionAutoSetCookie"] = BConfig.WebConfig.Session.SessionAutoSetCookie
|
|
||||||
m["BConfig.WebConfig.Session.SessionDomain"] = BConfig.WebConfig.Session.SessionDomain
|
|
||||||
m["BConfig.Log.AccessLogs"] = BConfig.Log.AccessLogs
|
|
||||||
m["BConfig.Log.FileLineNum"] = BConfig.Log.FileLineNum
|
|
||||||
m["BConfig.Log.Outputs"] = BConfig.Log.Outputs
|
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||||
tmpl = template.Must(tmpl.Parse(configTpl))
|
tmpl = template.Must(tmpl.Parse(configTpl))
|
||||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||||
@ -224,6 +178,28 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func list(root string, p interface{}, m map[string]interface{}) {
|
||||||
|
pt := reflect.TypeOf(p)
|
||||||
|
pv := reflect.ValueOf(p)
|
||||||
|
if pt.Kind() == reflect.Ptr {
|
||||||
|
pt = pt.Elem()
|
||||||
|
pv = pv.Elem()
|
||||||
|
}
|
||||||
|
for i := 0; i < pv.NumField(); i++ {
|
||||||
|
var key string
|
||||||
|
if root == "" {
|
||||||
|
key = pt.Field(i).Name
|
||||||
|
} else {
|
||||||
|
key = root + "." + pt.Field(i).Name
|
||||||
|
}
|
||||||
|
if pv.Field(i).Kind() == reflect.Struct {
|
||||||
|
list(key, pv.Field(i).Interface(), m)
|
||||||
|
} else {
|
||||||
|
m[key] = pv.Field(i).Interface()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func printTree(resultList *[][]string, t *Tree) {
|
func printTree(resultList *[][]string, t *Tree) {
|
||||||
for _, tr := range t.fixrouters {
|
for _, tr := range t.fixrouters {
|
||||||
printTree(resultList, tr)
|
printTree(resultList, tr)
|
||||||
|
72
admin_test.go
Normal file
72
admin_test.go
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package beego
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestList_01(t *testing.T) {
|
||||||
|
m := make(map[string]interface{})
|
||||||
|
list("BConfig", BConfig, m)
|
||||||
|
t.Log(m)
|
||||||
|
om := oldMap()
|
||||||
|
for k, v := range om {
|
||||||
|
if fmt.Sprint(m[k])!= fmt.Sprint(v) {
|
||||||
|
t.Log(k, "old-key",v,"new-key", m[k])
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func oldMap() map[string]interface{} {
|
||||||
|
m := make(map[string]interface{})
|
||||||
|
m["BConfig.AppName"] = BConfig.AppName
|
||||||
|
m["BConfig.RunMode"] = BConfig.RunMode
|
||||||
|
m["BConfig.RouterCaseSensitive"] = BConfig.RouterCaseSensitive
|
||||||
|
m["BConfig.ServerName"] = BConfig.ServerName
|
||||||
|
m["BConfig.RecoverPanic"] = BConfig.RecoverPanic
|
||||||
|
m["BConfig.CopyRequestBody"] = BConfig.CopyRequestBody
|
||||||
|
m["BConfig.EnableGzip"] = BConfig.EnableGzip
|
||||||
|
m["BConfig.MaxMemory"] = BConfig.MaxMemory
|
||||||
|
m["BConfig.EnableErrorsShow"] = BConfig.EnableErrorsShow
|
||||||
|
m["BConfig.Listen.Graceful"] = BConfig.Listen.Graceful
|
||||||
|
m["BConfig.Listen.ServerTimeOut"] = BConfig.Listen.ServerTimeOut
|
||||||
|
m["BConfig.Listen.ListenTCP4"] = BConfig.Listen.ListenTCP4
|
||||||
|
m["BConfig.Listen.EnableHTTP"] = BConfig.Listen.EnableHTTP
|
||||||
|
m["BConfig.Listen.HTTPAddr"] = BConfig.Listen.HTTPAddr
|
||||||
|
m["BConfig.Listen.HTTPPort"] = BConfig.Listen.HTTPPort
|
||||||
|
m["BConfig.Listen.EnableHTTPS"] = BConfig.Listen.EnableHTTPS
|
||||||
|
m["BConfig.Listen.HTTPSAddr"] = BConfig.Listen.HTTPSAddr
|
||||||
|
m["BConfig.Listen.HTTPSPort"] = BConfig.Listen.HTTPSPort
|
||||||
|
m["BConfig.Listen.HTTPSCertFile"] = BConfig.Listen.HTTPSCertFile
|
||||||
|
m["BConfig.Listen.HTTPSKeyFile"] = BConfig.Listen.HTTPSKeyFile
|
||||||
|
m["BConfig.Listen.EnableAdmin"] = BConfig.Listen.EnableAdmin
|
||||||
|
m["BConfig.Listen.AdminAddr"] = BConfig.Listen.AdminAddr
|
||||||
|
m["BConfig.Listen.AdminPort"] = BConfig.Listen.AdminPort
|
||||||
|
m["BConfig.Listen.EnableFcgi"] = BConfig.Listen.EnableFcgi
|
||||||
|
m["BConfig.Listen.EnableStdIo"] = BConfig.Listen.EnableStdIo
|
||||||
|
m["BConfig.WebConfig.AutoRender"] = BConfig.WebConfig.AutoRender
|
||||||
|
m["BConfig.WebConfig.EnableDocs"] = BConfig.WebConfig.EnableDocs
|
||||||
|
m["BConfig.WebConfig.FlashName"] = BConfig.WebConfig.FlashName
|
||||||
|
m["BConfig.WebConfig.FlashSeparator"] = BConfig.WebConfig.FlashSeparator
|
||||||
|
m["BConfig.WebConfig.DirectoryIndex"] = BConfig.WebConfig.DirectoryIndex
|
||||||
|
m["BConfig.WebConfig.StaticDir"] = BConfig.WebConfig.StaticDir
|
||||||
|
m["BConfig.WebConfig.StaticExtensionsToGzip"] = BConfig.WebConfig.StaticExtensionsToGzip
|
||||||
|
m["BConfig.WebConfig.TemplateLeft"] = BConfig.WebConfig.TemplateLeft
|
||||||
|
m["BConfig.WebConfig.TemplateRight"] = BConfig.WebConfig.TemplateRight
|
||||||
|
m["BConfig.WebConfig.ViewsPath"] = BConfig.WebConfig.ViewsPath
|
||||||
|
m["BConfig.WebConfig.EnableXSRF"] = BConfig.WebConfig.EnableXSRF
|
||||||
|
m["BConfig.WebConfig.XSRFExpire"] = BConfig.WebConfig.XSRFExpire
|
||||||
|
m["BConfig.WebConfig.Session.SessionOn"] = BConfig.WebConfig.Session.SessionOn
|
||||||
|
m["BConfig.WebConfig.Session.SessionProvider"] = BConfig.WebConfig.Session.SessionProvider
|
||||||
|
m["BConfig.WebConfig.Session.SessionName"] = BConfig.WebConfig.Session.SessionName
|
||||||
|
m["BConfig.WebConfig.Session.SessionGCMaxLifetime"] = BConfig.WebConfig.Session.SessionGCMaxLifetime
|
||||||
|
m["BConfig.WebConfig.Session.SessionProviderConfig"] = BConfig.WebConfig.Session.SessionProviderConfig
|
||||||
|
m["BConfig.WebConfig.Session.SessionCookieLifeTime"] = BConfig.WebConfig.Session.SessionCookieLifeTime
|
||||||
|
m["BConfig.WebConfig.Session.SessionAutoSetCookie"] = BConfig.WebConfig.Session.SessionAutoSetCookie
|
||||||
|
m["BConfig.WebConfig.Session.SessionDomain"] = BConfig.WebConfig.Session.SessionDomain
|
||||||
|
m["BConfig.Log.AccessLogs"] = BConfig.Log.AccessLogs
|
||||||
|
m["BConfig.Log.FileLineNum"] = BConfig.Log.FileLineNum
|
||||||
|
m["BConfig.Log.Outputs"] = BConfig.Log.Outputs
|
||||||
|
return m
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user