1
0
mirror of https://github.com/astaxie/beego.git synced 2024-06-30 11:34:14 +00:00

remove duplicated config initialization

This commit is contained in:
Pengfei Xue 2013-12-03 13:15:32 +08:00
parent 9c4414f995
commit 07312e240c

149
config.go
View File

@ -105,205 +105,132 @@ func ParseConfig() (err error) {
return err return err
} else { } else {
HttpAddr = AppConfig.String("httpaddr") HttpAddr = AppConfig.String("httpaddr")
if v, err := AppConfig.Int("httpport"); err == nil {
HttpPort = v
}
if v, err := AppConfig.Int("HttpPort"); err == nil { if v, err := AppConfig.Int("HttpPort"); err == nil {
HttpPort = v HttpPort = v
} }
if maxmemory, err := AppConfig.Int64("maxmemory"); err == nil {
MaxMemory = maxmemory
}
if maxmemory, err := AppConfig.Int64("MaxMemory"); err == nil { if maxmemory, err := AppConfig.Int64("MaxMemory"); err == nil {
MaxMemory = maxmemory MaxMemory = maxmemory
} }
AppName = AppConfig.String("appname")
if appname := AppConfig.String("AppName"); appname != "" { if appname := AppConfig.String("AppName"); appname != "" {
AppName = appname AppName = appname
} }
if runmode := AppConfig.String("runmode"); runmode != "" {
RunMode = runmode
}
if runmode := AppConfig.String("RunMode"); runmode != "" { if runmode := AppConfig.String("RunMode"); runmode != "" {
RunMode = runmode RunMode = runmode
} }
if autorender, err := AppConfig.Bool("autorender"); err == nil {
AutoRender = autorender
}
if autorender, err := AppConfig.Bool("AutoRender"); err == nil { if autorender, err := AppConfig.Bool("AutoRender"); err == nil {
AutoRender = autorender AutoRender = autorender
} }
if autorecover, err := AppConfig.Bool("autorecover"); err == nil {
RecoverPanic = autorecover
}
if autorecover, err := AppConfig.Bool("RecoverPanic"); err == nil { if autorecover, err := AppConfig.Bool("RecoverPanic"); err == nil {
RecoverPanic = autorecover RecoverPanic = autorecover
} }
if views := AppConfig.String("viewspath"); views != "" {
ViewsPath = views
}
if views := AppConfig.String("ViewsPath"); views != "" { if views := AppConfig.String("ViewsPath"); views != "" {
ViewsPath = views ViewsPath = views
} }
if sessionon, err := AppConfig.Bool("sessionon"); err == nil {
SessionOn = sessionon
}
if sessionon, err := AppConfig.Bool("SessionOn"); err == nil { if sessionon, err := AppConfig.Bool("SessionOn"); err == nil {
SessionOn = sessionon SessionOn = sessionon
} }
if sessProvider := AppConfig.String("sessionprovider"); sessProvider != "" {
SessionProvider = sessProvider
}
if sessProvider := AppConfig.String("SessionProvider"); sessProvider != "" { if sessProvider := AppConfig.String("SessionProvider"); sessProvider != "" {
SessionProvider = sessProvider SessionProvider = sessProvider
} }
if sessName := AppConfig.String("sessionname"); sessName != "" {
SessionName = sessName
}
if sessName := AppConfig.String("SessionName"); sessName != "" { if sessName := AppConfig.String("SessionName"); sessName != "" {
SessionName = sessName SessionName = sessName
} }
if sesssavepath := AppConfig.String("sessionsavepath"); sesssavepath != "" {
SessionSavePath = sesssavepath
}
if sesssavepath := AppConfig.String("SessionSavePath"); sesssavepath != "" { if sesssavepath := AppConfig.String("SessionSavePath"); sesssavepath != "" {
SessionSavePath = sesssavepath SessionSavePath = sesssavepath
} }
if sesshashfunc := AppConfig.String("sessionhashfunc"); sesshashfunc != "" {
SessionHashFunc = sesshashfunc
}
if sesshashfunc := AppConfig.String("SessionHashFunc"); sesshashfunc != "" { if sesshashfunc := AppConfig.String("SessionHashFunc"); sesshashfunc != "" {
SessionHashFunc = sesshashfunc SessionHashFunc = sesshashfunc
} }
if sesshashkey := AppConfig.String("sessionhashkey"); sesshashkey != "" {
SessionHashKey = sesshashkey
}
if sesshashkey := AppConfig.String("SessionHashKey"); sesshashkey != "" { if sesshashkey := AppConfig.String("SessionHashKey"); sesshashkey != "" {
SessionHashKey = sesshashkey SessionHashKey = sesshashkey
} }
if sessMaxLifeTime, err := AppConfig.Int("sessiongcmaxlifetime"); err == nil && sessMaxLifeTime != 0 {
int64val, _ := strconv.ParseInt(strconv.Itoa(sessMaxLifeTime), 10, 64)
SessionGCMaxLifetime = int64val
}
if sessMaxLifeTime, err := AppConfig.Int("SessionGCMaxLifetime"); err == nil && sessMaxLifeTime != 0 { if sessMaxLifeTime, err := AppConfig.Int("SessionGCMaxLifetime"); err == nil && sessMaxLifeTime != 0 {
int64val, _ := strconv.ParseInt(strconv.Itoa(sessMaxLifeTime), 10, 64) int64val, _ := strconv.ParseInt(strconv.Itoa(sessMaxLifeTime), 10, 64)
SessionGCMaxLifetime = int64val SessionGCMaxLifetime = int64val
} }
if sesscookielifetime, err := AppConfig.Int("sessioncookielifelime"); err == nil && sesscookielifetime != 0 {
SessionCookieLifeTime = sesscookielifetime
}
if sesscookielifetime, err := AppConfig.Int("SessionCookieLifeTime"); err == nil && sesscookielifetime != 0 { if sesscookielifetime, err := AppConfig.Int("SessionCookieLifeTime"); err == nil && sesscookielifetime != 0 {
SessionCookieLifeTime = sesscookielifetime SessionCookieLifeTime = sesscookielifetime
} }
if usefcgi, err := AppConfig.Bool("usefcgi"); err == nil {
UseFcgi = usefcgi
}
if usefcgi, err := AppConfig.Bool("UseFcgi"); err == nil { if usefcgi, err := AppConfig.Bool("UseFcgi"); err == nil {
UseFcgi = usefcgi UseFcgi = usefcgi
} }
if enablegzip, err := AppConfig.Bool("enablegzip"); err == nil {
EnableGzip = enablegzip
}
if enablegzip, err := AppConfig.Bool("EnableGzip"); err == nil { if enablegzip, err := AppConfig.Bool("EnableGzip"); err == nil {
EnableGzip = enablegzip EnableGzip = enablegzip
} }
if directoryindex, err := AppConfig.Bool("directoryindex"); err == nil {
DirectoryIndex = directoryindex
}
if directoryindex, err := AppConfig.Bool("DirectoryIndex"); err == nil { if directoryindex, err := AppConfig.Bool("DirectoryIndex"); err == nil {
DirectoryIndex = directoryindex DirectoryIndex = directoryindex
} }
if hotupdate, err := AppConfig.Bool("hotupdate"); err == nil {
EnableHotUpdate = hotupdate
}
if hotupdate, err := AppConfig.Bool("HotUpdate"); err == nil { if hotupdate, err := AppConfig.Bool("HotUpdate"); err == nil {
EnableHotUpdate = hotupdate EnableHotUpdate = hotupdate
} }
if timeout, err := AppConfig.Int64("httpservertimeout"); err == nil {
HttpServerTimeOut = timeout
}
if timeout, err := AppConfig.Int64("HttpServerTimeOut"); err == nil { if timeout, err := AppConfig.Int64("HttpServerTimeOut"); err == nil {
HttpServerTimeOut = timeout HttpServerTimeOut = timeout
} }
if errorsshow, err := AppConfig.Bool("errorsshow"); err == nil {
ErrorsShow = errorsshow
}
if errorsshow, err := AppConfig.Bool("ErrorsShow"); err == nil { if errorsshow, err := AppConfig.Bool("ErrorsShow"); err == nil {
ErrorsShow = errorsshow ErrorsShow = errorsshow
} }
if copyrequestbody, err := AppConfig.Bool("copyrequestbody"); err == nil {
CopyRequestBody = copyrequestbody
}
if copyrequestbody, err := AppConfig.Bool("CopyRequestBody"); err == nil { if copyrequestbody, err := AppConfig.Bool("CopyRequestBody"); err == nil {
CopyRequestBody = copyrequestbody CopyRequestBody = copyrequestbody
} }
if xsrfkey := AppConfig.String("xsrfkey"); xsrfkey != "" {
XSRFKEY = xsrfkey
}
if xsrfkey := AppConfig.String("XSRFKEY"); xsrfkey != "" { if xsrfkey := AppConfig.String("XSRFKEY"); xsrfkey != "" {
XSRFKEY = xsrfkey XSRFKEY = xsrfkey
} }
if enablexsrf, err := AppConfig.Bool("enablexsrf"); err == nil {
EnableXSRF = enablexsrf
}
if enablexsrf, err := AppConfig.Bool("EnableXSRF"); err == nil { if enablexsrf, err := AppConfig.Bool("EnableXSRF"); err == nil {
EnableXSRF = enablexsrf EnableXSRF = enablexsrf
} }
if expire, err := AppConfig.Int("xsrfexpire"); err == nil {
XSRFExpire = expire
}
if expire, err := AppConfig.Int("XSRFExpire"); err == nil { if expire, err := AppConfig.Int("XSRFExpire"); err == nil {
XSRFExpire = expire XSRFExpire = expire
} }
if tplleft := AppConfig.String("templateleft"); tplleft != "" {
TemplateLeft = tplleft
}
if tplleft := AppConfig.String("TemplateLeft"); tplleft != "" { if tplleft := AppConfig.String("TemplateLeft"); tplleft != "" {
TemplateLeft = tplleft TemplateLeft = tplleft
} }
if tplright := AppConfig.String("templateright"); tplright != "" {
TemplateRight = tplright
}
if tplright := AppConfig.String("TemplateRight"); tplright != "" { if tplright := AppConfig.String("TemplateRight"); tplright != "" {
TemplateRight = tplright TemplateRight = tplright
} }
if httptls, err := AppConfig.Bool("httptls"); err == nil {
HttpTLS = httptls
}
if httptls, err := AppConfig.Bool("HttpTLS"); err == nil { if httptls, err := AppConfig.Bool("HttpTLS"); err == nil {
HttpTLS = httptls HttpTLS = httptls
} }
if certfile := AppConfig.String("httpcertfile"); certfile != "" { if certfile := AppConfig.String("httpcertfile"); certfile != "" {
HttpCertFile = certfile HttpCertFile = certfile
} }
if certfile := AppConfig.String("HttpCertFile"); certfile != "" {
HttpCertFile = certfile
}
if keyfile := AppConfig.String("httpkeyfile"); keyfile != "" {
HttpKeyFile = keyfile
}
if keyfile := AppConfig.String("HttpKeyFile"); keyfile != "" { if keyfile := AppConfig.String("HttpKeyFile"); keyfile != "" {
HttpKeyFile = keyfile HttpKeyFile = keyfile
} }
if serverName := AppConfig.String("beegoserverName"); serverName != "" {
BeegoServerName = serverName
}
if serverName := AppConfig.String("BeegoServerName"); serverName != "" { if serverName := AppConfig.String("BeegoServerName"); serverName != "" {
BeegoServerName = serverName BeegoServerName = serverName
} }
if sd := AppConfig.String("staticdir"); sd != "" {
for k := range StaticDir {
delete(StaticDir, k)
}
sds := strings.Fields(sd)
for _, v := range sds {
if url2fsmap := strings.SplitN(v, ":", 2); len(url2fsmap) == 2 {
StaticDir["/"+url2fsmap[0]] = url2fsmap[1]
} else {
StaticDir["/"+url2fsmap[0]] = url2fsmap[0]
}
}
}
if sd := AppConfig.String("StaticDir"); sd != "" { if sd := AppConfig.String("StaticDir"); sd != "" {
for k := range StaticDir { for k := range StaticDir {
delete(StaticDir, k) delete(StaticDir, k)
@ -317,21 +244,15 @@ func ParseConfig() (err error) {
} }
} }
} }
if enableadmin, err := AppConfig.Bool("enableadmin"); err == nil {
EnableAdmin = enableadmin
}
if enableadmin, err := AppConfig.Bool("EnableAdmin"); err == nil { if enableadmin, err := AppConfig.Bool("EnableAdmin"); err == nil {
EnableAdmin = enableadmin EnableAdmin = enableadmin
} }
if adminhttpaddr := AppConfig.String("admintttpaddr"); adminhttpaddr != "" {
AdminHttpAddr = adminhttpaddr
}
if adminhttpaddr := AppConfig.String("AdminHttpAddr"); adminhttpaddr != "" { if adminhttpaddr := AppConfig.String("AdminHttpAddr"); adminhttpaddr != "" {
AdminHttpAddr = adminhttpaddr AdminHttpAddr = adminhttpaddr
} }
if adminhttpport, err := AppConfig.Int("adminhttpport"); err == nil {
AdminHttpPort = adminhttpport
}
if adminhttpport, err := AppConfig.Int("AdminHttpPort"); err == nil { if adminhttpport, err := AppConfig.Int("AdminHttpPort"); err == nil {
AdminHttpPort = adminhttpport AdminHttpPort = adminhttpport
} }