Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
d9e6250d
Commit
d9e6250d
authored
Jan 26, 2016
by
youngsterxyf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix config logic
parent
cbc7f43e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
28 deletions
+64
-28
beego.go
beego.go
+1
-11
config.go
config.go
+63
-17
No files found.
beego.go
View file @
d9e6250d
...
...
@@ -15,7 +15,6 @@
package
beego
import
(
"fmt"
"os"
"path/filepath"
"strconv"
...
...
@@ -76,15 +75,6 @@ func initBeforeHTTPRun() {
}
*/
var
err
error
//init log
for
adaptor
,
config
:=
range
BConfig
.
Log
.
Outputs
{
err
=
BeeLogger
.
SetLogger
(
adaptor
,
config
)
if
err
!=
nil
{
fmt
.
Printf
(
"%s with the config `%s` got err:%s
\n
"
,
adaptor
,
config
,
err
)
}
}
SetLogFuncCall
(
BConfig
.
Log
.
FileLineNum
)
//init hooks
AddAPPStartHook
(
registerMime
)
...
...
@@ -95,7 +85,7 @@ func initBeforeHTTPRun() {
AddAPPStartHook
(
registerAdmin
)
for
_
,
hk
:=
range
hooks
{
if
err
:
=
hk
();
err
!=
nil
{
if
err
=
hk
();
err
!=
nil
{
panic
(
err
)
}
}
...
...
config.go
View file @
d9e6250d
...
...
@@ -19,6 +19,7 @@ import (
"os"
"path/filepath"
"strings"
"fmt"
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/session"
...
...
@@ -103,14 +104,15 @@ var (
BConfig
*
Config
// AppConfig is the instance of Config, store the config information from file
AppConfig
*
beegoAppConfig
// AppConfigPath is the path to the config files
AppConfigPath
string
// AppConfigProvider is the provider for the config, default is ini
AppConfigProvider
=
"ini"
// TemplateCache stores template caching
TemplateCache
map
[
string
]
*
template
.
Template
// GlobalSessions is the instance for the session manager
GlobalSessions
*
session
.
Manager
// AppConfigPath is the path to the config files
AppConfigPath
string
// AppConfigProvider is the provider for the config, default is ini
AppConfigProvider
=
"ini"
)
func
init
()
{
...
...
@@ -173,22 +175,26 @@ func init() {
Outputs
:
map
[
string
]
string
{
"console"
:
""
},
},
}
ParseConfig
()
AppConfigPath
=
getDefaultAppConfigPath
()
if
!
utils
.
FileExists
(
AppConfigPath
)
{
AppConfig
=
&
beegoAppConfig
{
config
.
NewFakeConfig
()}
return
}
parseConfig
(
AppConfigPath
)
}
func
getDefaultAppConfigPath
()
string
{
// default config path
AppPath
,
_
:=
filepath
.
Abs
(
filepath
.
Dir
(
os
.
Args
[
0
]))
return
filepath
.
Join
(
AppPath
,
"conf"
,
"app.conf"
)
}
// ParseConfig parsed default config file.
// now only support ini, next will support json.
func
ParseConfig
()
(
err
error
)
{
if
AppConfigPath
==
""
{
// initialize default configurations
AppPath
,
_
:=
filepath
.
Abs
(
filepath
.
Dir
(
os
.
Args
[
0
]))
AppConfigPath
=
filepath
.
Join
(
AppPath
,
"conf"
,
"app.conf"
)
if
!
utils
.
FileExists
(
AppConfigPath
)
{
AppConfig
=
&
beegoAppConfig
{
config
.
NewFakeConfig
()}
return
}
}
AppConfig
,
err
=
newAppConfig
(
AppConfigProvider
,
AppConfigPath
)
func
parseConfig
(
appConfigPath
string
)
(
err
error
)
{
AppConfig
,
err
=
newAppConfig
(
AppConfigProvider
,
appConfigPath
)
if
err
!=
nil
{
return
err
}
...
...
@@ -242,6 +248,8 @@ func ParseConfig() (err error) {
BConfig
.
WebConfig
.
Session
.
SessionCookieLifeTime
=
AppConfig
.
DefaultInt
(
"SessionCookieLifeTime"
,
BConfig
.
WebConfig
.
Session
.
SessionCookieLifeTime
)
BConfig
.
WebConfig
.
Session
.
SessionAutoSetCookie
=
AppConfig
.
DefaultBool
(
"SessionAutoSetCookie"
,
BConfig
.
WebConfig
.
Session
.
SessionAutoSetCookie
)
BConfig
.
WebConfig
.
Session
.
SessionDomain
=
AppConfig
.
DefaultString
(
"SessionDomain"
,
BConfig
.
WebConfig
.
Session
.
SessionDomain
)
BConfig
.
Log
.
AccessLogs
=
AppConfig
.
DefaultBool
(
"LogAccessLogs"
,
BConfig
.
Log
.
AccessLogs
)
BConfig
.
Log
.
FileLineNum
=
AppConfig
.
DefaultBool
(
"LogFileLineNum"
,
BConfig
.
Log
.
FileLineNum
)
if
sd
:=
AppConfig
.
String
(
"StaticDir"
);
sd
!=
""
{
for
k
:=
range
BConfig
.
WebConfig
.
StaticDir
{
...
...
@@ -274,9 +282,47 @@ func ParseConfig() (err error) {
BConfig
.
WebConfig
.
StaticExtensionsToGzip
=
fileExts
}
}
if
lo
:=
AppConfig
.
String
(
"LogOutputs"
);
lo
!=
""
{
los
:=
strings
.
Split
(
lo
,
";"
)
for
_
,
v
:=
range
los
{
if
logType2Config
:=
strings
.
SplitN
(
v
,
","
,
2
);
len
(
logType2Config
)
==
2
{
BConfig
.
Log
.
Outputs
[
logType2Config
[
0
]]
=
logType2Config
[
1
]
}
else
{
continue
}
}
}
//init log
BeeLogger
.
Close
()
for
adaptor
,
config
:=
range
BConfig
.
Log
.
Outputs
{
err
=
BeeLogger
.
SetLogger
(
adaptor
,
config
)
if
err
!=
nil
{
fmt
.
Printf
(
"%s with the config `%s` got err:%s
\n
"
,
adaptor
,
config
,
err
)
}
}
SetLogFuncCall
(
BConfig
.
Log
.
FileLineNum
)
return
nil
}
// LoadAppConfig allow developer to apply a config file
func
LoadAppConfig
(
configPath
string
,
adapterName
string
)
error
{
absConfigPath
,
err
:=
filepath
.
Abs
(
configPath
)
if
err
!=
nil
{
return
err
}
if
absConfigPath
==
AppConfigPath
{
return
nil
}
AppConfigPath
=
absConfigPath
AppConfigProvider
=
adapterName
return
parseConfig
(
AppConfigPath
)
}
type
beegoAppConfig
struct
{
innerConfig
config
.
Configer
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment