Merge pull request #327 from pengfei-xue/devel
remove duplicated config initialization
Showing
1 changed file
with
36 additions
and
115 deletions
| ... | @@ -104,206 +104,133 @@ func ParseConfig() (err error) { | ... | @@ -104,206 +104,133 @@ func ParseConfig() (err error) { |
| 104 | if err != nil { | 104 | if err != nil { |
| 105 | return err | 105 | return err |
| 106 | } else { | 106 | } else { |
| 107 | HttpAddr = AppConfig.String("httpaddr") | 107 | HttpAddr = AppConfig.String("HttpAddr") |
| 108 | if v, err := AppConfig.Int("httpport"); err == nil { | 108 | |
| 109 | HttpPort = v | ||
| 110 | } | ||
| 111 | if v, err := AppConfig.Int("HttpPort"); err == nil { | 109 | if v, err := AppConfig.Int("HttpPort"); err == nil { |
| 112 | HttpPort = v | 110 | HttpPort = v |
| 113 | } | 111 | } |
| 114 | if maxmemory, err := AppConfig.Int64("maxmemory"); err == nil { | 112 | |
| 115 | MaxMemory = maxmemory | ||
| 116 | } | ||
| 117 | if maxmemory, err := AppConfig.Int64("MaxMemory"); err == nil { | 113 | if maxmemory, err := AppConfig.Int64("MaxMemory"); err == nil { |
| 118 | MaxMemory = maxmemory | 114 | MaxMemory = maxmemory |
| 119 | } | 115 | } |
| 120 | AppName = AppConfig.String("appname") | 116 | |
| 121 | if appname := AppConfig.String("AppName"); appname != "" { | 117 | if appname := AppConfig.String("AppName"); appname != "" { |
| 122 | AppName = appname | 118 | AppName = appname |
| 123 | } | 119 | } |
| 124 | if runmode := AppConfig.String("runmode"); runmode != "" { | 120 | |
| 125 | RunMode = runmode | ||
| 126 | } | ||
| 127 | if runmode := AppConfig.String("RunMode"); runmode != "" { | 121 | if runmode := AppConfig.String("RunMode"); runmode != "" { |
| 128 | RunMode = runmode | 122 | RunMode = runmode |
| 129 | } | 123 | } |
| 130 | if autorender, err := AppConfig.Bool("autorender"); err == nil { | 124 | |
| 131 | AutoRender = autorender | ||
| 132 | } | ||
| 133 | if autorender, err := AppConfig.Bool("AutoRender"); err == nil { | 125 | if autorender, err := AppConfig.Bool("AutoRender"); err == nil { |
| 134 | AutoRender = autorender | 126 | AutoRender = autorender |
| 135 | } | 127 | } |
| 136 | if autorecover, err := AppConfig.Bool("autorecover"); err == nil { | 128 | |
| 137 | RecoverPanic = autorecover | ||
| 138 | } | ||
| 139 | if autorecover, err := AppConfig.Bool("RecoverPanic"); err == nil { | 129 | if autorecover, err := AppConfig.Bool("RecoverPanic"); err == nil { |
| 140 | RecoverPanic = autorecover | 130 | RecoverPanic = autorecover |
| 141 | } | 131 | } |
| 142 | if views := AppConfig.String("viewspath"); views != "" { | 132 | |
| 143 | ViewsPath = views | ||
| 144 | } | ||
| 145 | if views := AppConfig.String("ViewsPath"); views != "" { | 133 | if views := AppConfig.String("ViewsPath"); views != "" { |
| 146 | ViewsPath = views | 134 | ViewsPath = views |
| 147 | } | 135 | } |
| 148 | if sessionon, err := AppConfig.Bool("sessionon"); err == nil { | 136 | |
| 149 | SessionOn = sessionon | ||
| 150 | } | ||
| 151 | if sessionon, err := AppConfig.Bool("SessionOn"); err == nil { | 137 | if sessionon, err := AppConfig.Bool("SessionOn"); err == nil { |
| 152 | SessionOn = sessionon | 138 | SessionOn = sessionon |
| 153 | } | 139 | } |
| 154 | if sessProvider := AppConfig.String("sessionprovider"); sessProvider != "" { | 140 | |
| 155 | SessionProvider = sessProvider | ||
| 156 | } | ||
| 157 | if sessProvider := AppConfig.String("SessionProvider"); sessProvider != "" { | 141 | if sessProvider := AppConfig.String("SessionProvider"); sessProvider != "" { |
| 158 | SessionProvider = sessProvider | 142 | SessionProvider = sessProvider |
| 159 | } | 143 | } |
| 160 | if sessName := AppConfig.String("sessionname"); sessName != "" { | 144 | |
| 161 | SessionName = sessName | ||
| 162 | } | ||
| 163 | if sessName := AppConfig.String("SessionName"); sessName != "" { | 145 | if sessName := AppConfig.String("SessionName"); sessName != "" { |
| 164 | SessionName = sessName | 146 | SessionName = sessName |
| 165 | } | 147 | } |
| 166 | if sesssavepath := AppConfig.String("sessionsavepath"); sesssavepath != "" { | 148 | |
| 167 | SessionSavePath = sesssavepath | ||
| 168 | } | ||
| 169 | if sesssavepath := AppConfig.String("SessionSavePath"); sesssavepath != "" { | 149 | if sesssavepath := AppConfig.String("SessionSavePath"); sesssavepath != "" { |
| 170 | SessionSavePath = sesssavepath | 150 | SessionSavePath = sesssavepath |
| 171 | } | 151 | } |
| 172 | if sesshashfunc := AppConfig.String("sessionhashfunc"); sesshashfunc != "" { | 152 | |
| 173 | SessionHashFunc = sesshashfunc | ||
| 174 | } | ||
| 175 | if sesshashfunc := AppConfig.String("SessionHashFunc"); sesshashfunc != "" { | 153 | if sesshashfunc := AppConfig.String("SessionHashFunc"); sesshashfunc != "" { |
| 176 | SessionHashFunc = sesshashfunc | 154 | SessionHashFunc = sesshashfunc |
| 177 | } | 155 | } |
| 178 | if sesshashkey := AppConfig.String("sessionhashkey"); sesshashkey != "" { | 156 | |
| 179 | SessionHashKey = sesshashkey | ||
| 180 | } | ||
| 181 | if sesshashkey := AppConfig.String("SessionHashKey"); sesshashkey != "" { | 157 | if sesshashkey := AppConfig.String("SessionHashKey"); sesshashkey != "" { |
| 182 | SessionHashKey = sesshashkey | 158 | SessionHashKey = sesshashkey |
| 183 | } | 159 | } |
| 184 | if sessMaxLifeTime, err := AppConfig.Int("sessiongcmaxlifetime"); err == nil && sessMaxLifeTime != 0 { | 160 | |
| 185 | int64val, _ := strconv.ParseInt(strconv.Itoa(sessMaxLifeTime), 10, 64) | ||
| 186 | SessionGCMaxLifetime = int64val | ||
| 187 | } | ||
| 188 | if sessMaxLifeTime, err := AppConfig.Int("SessionGCMaxLifetime"); err == nil && sessMaxLifeTime != 0 { | 161 | if sessMaxLifeTime, err := AppConfig.Int("SessionGCMaxLifetime"); err == nil && sessMaxLifeTime != 0 { |
| 189 | int64val, _ := strconv.ParseInt(strconv.Itoa(sessMaxLifeTime), 10, 64) | 162 | int64val, _ := strconv.ParseInt(strconv.Itoa(sessMaxLifeTime), 10, 64) |
| 190 | SessionGCMaxLifetime = int64val | 163 | SessionGCMaxLifetime = int64val |
| 191 | } | 164 | } |
| 192 | if sesscookielifetime, err := AppConfig.Int("sessioncookielifelime"); err == nil && sesscookielifetime != 0 { | 165 | |
| 193 | SessionCookieLifeTime = sesscookielifetime | ||
| 194 | } | ||
| 195 | if sesscookielifetime, err := AppConfig.Int("SessionCookieLifeTime"); err == nil && sesscookielifetime != 0 { | 166 | if sesscookielifetime, err := AppConfig.Int("SessionCookieLifeTime"); err == nil && sesscookielifetime != 0 { |
| 196 | SessionCookieLifeTime = sesscookielifetime | 167 | SessionCookieLifeTime = sesscookielifetime |
| 197 | } | 168 | } |
| 198 | if usefcgi, err := AppConfig.Bool("usefcgi"); err == nil { | 169 | |
| 199 | UseFcgi = usefcgi | ||
| 200 | } | ||
| 201 | if usefcgi, err := AppConfig.Bool("UseFcgi"); err == nil { | 170 | if usefcgi, err := AppConfig.Bool("UseFcgi"); err == nil { |
| 202 | UseFcgi = usefcgi | 171 | UseFcgi = usefcgi |
| 203 | } | 172 | } |
| 204 | if enablegzip, err := AppConfig.Bool("enablegzip"); err == nil { | 173 | |
| 205 | EnableGzip = enablegzip | ||
| 206 | } | ||
| 207 | if enablegzip, err := AppConfig.Bool("EnableGzip"); err == nil { | 174 | if enablegzip, err := AppConfig.Bool("EnableGzip"); err == nil { |
| 208 | EnableGzip = enablegzip | 175 | EnableGzip = enablegzip |
| 209 | } | 176 | } |
| 210 | if directoryindex, err := AppConfig.Bool("directoryindex"); err == nil { | 177 | |
| 211 | DirectoryIndex = directoryindex | ||
| 212 | } | ||
| 213 | if directoryindex, err := AppConfig.Bool("DirectoryIndex"); err == nil { | 178 | if directoryindex, err := AppConfig.Bool("DirectoryIndex"); err == nil { |
| 214 | DirectoryIndex = directoryindex | 179 | DirectoryIndex = directoryindex |
| 215 | } | 180 | } |
| 216 | if hotupdate, err := AppConfig.Bool("hotupdate"); err == nil { | 181 | |
| 217 | EnableHotUpdate = hotupdate | ||
| 218 | } | ||
| 219 | if hotupdate, err := AppConfig.Bool("HotUpdate"); err == nil { | 182 | if hotupdate, err := AppConfig.Bool("HotUpdate"); err == nil { |
| 220 | EnableHotUpdate = hotupdate | 183 | EnableHotUpdate = hotupdate |
| 221 | } | 184 | } |
| 222 | if timeout, err := AppConfig.Int64("httpservertimeout"); err == nil { | 185 | |
| 223 | HttpServerTimeOut = timeout | ||
| 224 | } | ||
| 225 | if timeout, err := AppConfig.Int64("HttpServerTimeOut"); err == nil { | 186 | if timeout, err := AppConfig.Int64("HttpServerTimeOut"); err == nil { |
| 226 | HttpServerTimeOut = timeout | 187 | HttpServerTimeOut = timeout |
| 227 | } | 188 | } |
| 228 | if errorsshow, err := AppConfig.Bool("errorsshow"); err == nil { | 189 | |
| 229 | ErrorsShow = errorsshow | ||
| 230 | } | ||
| 231 | if errorsshow, err := AppConfig.Bool("ErrorsShow"); err == nil { | 190 | if errorsshow, err := AppConfig.Bool("ErrorsShow"); err == nil { |
| 232 | ErrorsShow = errorsshow | 191 | ErrorsShow = errorsshow |
| 233 | } | 192 | } |
| 234 | if copyrequestbody, err := AppConfig.Bool("copyrequestbody"); err == nil { | 193 | |
| 235 | CopyRequestBody = copyrequestbody | ||
| 236 | } | ||
| 237 | if copyrequestbody, err := AppConfig.Bool("CopyRequestBody"); err == nil { | 194 | if copyrequestbody, err := AppConfig.Bool("CopyRequestBody"); err == nil { |
| 238 | CopyRequestBody = copyrequestbody | 195 | CopyRequestBody = copyrequestbody |
| 239 | } | 196 | } |
| 240 | if xsrfkey := AppConfig.String("xsrfkey"); xsrfkey != "" { | 197 | |
| 241 | XSRFKEY = xsrfkey | ||
| 242 | } | ||
| 243 | if xsrfkey := AppConfig.String("XSRFKEY"); xsrfkey != "" { | 198 | if xsrfkey := AppConfig.String("XSRFKEY"); xsrfkey != "" { |
| 244 | XSRFKEY = xsrfkey | 199 | XSRFKEY = xsrfkey |
| 245 | } | 200 | } |
| 246 | if enablexsrf, err := AppConfig.Bool("enablexsrf"); err == nil { | 201 | |
| 247 | EnableXSRF = enablexsrf | ||
| 248 | } | ||
| 249 | if enablexsrf, err := AppConfig.Bool("EnableXSRF"); err == nil { | 202 | if enablexsrf, err := AppConfig.Bool("EnableXSRF"); err == nil { |
| 250 | EnableXSRF = enablexsrf | 203 | EnableXSRF = enablexsrf |
| 251 | } | 204 | } |
| 252 | if expire, err := AppConfig.Int("xsrfexpire"); err == nil { | 205 | |
| 253 | XSRFExpire = expire | ||
| 254 | } | ||
| 255 | if expire, err := AppConfig.Int("XSRFExpire"); err == nil { | 206 | if expire, err := AppConfig.Int("XSRFExpire"); err == nil { |
| 256 | XSRFExpire = expire | 207 | XSRFExpire = expire |
| 257 | } | 208 | } |
| 258 | if tplleft := AppConfig.String("templateleft"); tplleft != "" { | 209 | |
| 259 | TemplateLeft = tplleft | ||
| 260 | } | ||
| 261 | if tplleft := AppConfig.String("TemplateLeft"); tplleft != "" { | 210 | if tplleft := AppConfig.String("TemplateLeft"); tplleft != "" { |
| 262 | TemplateLeft = tplleft | 211 | TemplateLeft = tplleft |
| 263 | } | 212 | } |
| 264 | if tplright := AppConfig.String("templateright"); tplright != "" { | 213 | |
| 265 | TemplateRight = tplright | ||
| 266 | } | ||
| 267 | if tplright := AppConfig.String("TemplateRight"); tplright != "" { | 214 | if tplright := AppConfig.String("TemplateRight"); tplright != "" { |
| 268 | TemplateRight = tplright | 215 | TemplateRight = tplright |
| 269 | } | 216 | } |
| 270 | if httptls, err := AppConfig.Bool("httptls"); err == nil { | 217 | |
| 271 | HttpTLS = httptls | ||
| 272 | } | ||
| 273 | if httptls, err := AppConfig.Bool("HttpTLS"); err == nil { | 218 | if httptls, err := AppConfig.Bool("HttpTLS"); err == nil { |
| 274 | HttpTLS = httptls | 219 | HttpTLS = httptls |
| 275 | } | 220 | } |
| 276 | if certfile := AppConfig.String("httpcertfile"); certfile != "" { | 221 | |
| 277 | HttpCertFile = certfile | ||
| 278 | } | ||
| 279 | if certfile := AppConfig.String("HttpCertFile"); certfile != "" { | 222 | if certfile := AppConfig.String("HttpCertFile"); certfile != "" { |
| 280 | HttpCertFile = certfile | 223 | HttpCertFile = certfile |
| 281 | } | 224 | } |
| 282 | if keyfile := AppConfig.String("httpkeyfile"); keyfile != "" { | 225 | |
| 283 | HttpKeyFile = keyfile | ||
| 284 | } | ||
| 285 | if keyfile := AppConfig.String("HttpKeyFile"); keyfile != "" { | 226 | if keyfile := AppConfig.String("HttpKeyFile"); keyfile != "" { |
| 286 | HttpKeyFile = keyfile | 227 | HttpKeyFile = keyfile |
| 287 | } | 228 | } |
| 288 | if serverName := AppConfig.String("beegoserverName"); serverName != "" { | 229 | |
| 289 | BeegoServerName = serverName | ||
| 290 | } | ||
| 291 | if serverName := AppConfig.String("BeegoServerName"); serverName != "" { | 230 | if serverName := AppConfig.String("BeegoServerName"); serverName != "" { |
| 292 | BeegoServerName = serverName | 231 | BeegoServerName = serverName |
| 293 | } | 232 | } |
| 294 | if sd := AppConfig.String("staticdir"); sd != "" { | 233 | |
| 295 | for k := range StaticDir { | ||
| 296 | delete(StaticDir, k) | ||
| 297 | } | ||
| 298 | sds := strings.Fields(sd) | ||
| 299 | for _, v := range sds { | ||
| 300 | if url2fsmap := strings.SplitN(v, ":", 2); len(url2fsmap) == 2 { | ||
| 301 | StaticDir["/"+url2fsmap[0]] = url2fsmap[1] | ||
| 302 | } else { | ||
| 303 | StaticDir["/"+url2fsmap[0]] = url2fsmap[0] | ||
| 304 | } | ||
| 305 | } | ||
| 306 | } | ||
| 307 | if sd := AppConfig.String("StaticDir"); sd != "" { | 234 | if sd := AppConfig.String("StaticDir"); sd != "" { |
| 308 | for k := range StaticDir { | 235 | for k := range StaticDir { |
| 309 | delete(StaticDir, k) | 236 | delete(StaticDir, k) |
| ... | @@ -317,21 +244,15 @@ func ParseConfig() (err error) { | ... | @@ -317,21 +244,15 @@ func ParseConfig() (err error) { |
| 317 | } | 244 | } |
| 318 | } | 245 | } |
| 319 | } | 246 | } |
| 320 | if enableadmin, err := AppConfig.Bool("enableadmin"); err == nil { | 247 | |
| 321 | EnableAdmin = enableadmin | ||
| 322 | } | ||
| 323 | if enableadmin, err := AppConfig.Bool("EnableAdmin"); err == nil { | 248 | if enableadmin, err := AppConfig.Bool("EnableAdmin"); err == nil { |
| 324 | EnableAdmin = enableadmin | 249 | EnableAdmin = enableadmin |
| 325 | } | 250 | } |
| 326 | if adminhttpaddr := AppConfig.String("admintttpaddr"); adminhttpaddr != "" { | 251 | |
| 327 | AdminHttpAddr = adminhttpaddr | ||
| 328 | } | ||
| 329 | if adminhttpaddr := AppConfig.String("AdminHttpAddr"); adminhttpaddr != "" { | 252 | if adminhttpaddr := AppConfig.String("AdminHttpAddr"); adminhttpaddr != "" { |
| 330 | AdminHttpAddr = adminhttpaddr | 253 | AdminHttpAddr = adminhttpaddr |
| 331 | } | 254 | } |
| 332 | if adminhttpport, err := AppConfig.Int("adminhttpport"); err == nil { | 255 | |
| 333 | AdminHttpPort = adminhttpport | ||
| 334 | } | ||
| 335 | if adminhttpport, err := AppConfig.Int("AdminHttpPort"); err == nil { | 256 | if adminhttpport, err := AppConfig.Int("AdminHttpPort"); err == nil { |
| 336 | AdminHttpPort = adminhttpport | 257 | AdminHttpPort = adminhttpport |
| 337 | } | 258 | } | ... | ... |
-
Please register or sign in to post a comment