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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
26 deletions
+62
-26
beego.go
beego.go
+1
-11
config.go
config.go
+61
-15
No files found.
beego.go
View file @
d9e6250d
...
@@ -15,7 +15,6 @@
...
@@ -15,7 +15,6 @@
package
beego
package
beego
import
(
import
(
"fmt"
"os"
"os"
"path/filepath"
"path/filepath"
"strconv"
"strconv"
...
@@ -76,15 +75,6 @@ func initBeforeHTTPRun() {
...
@@ -76,15 +75,6 @@ func initBeforeHTTPRun() {
}
}
*/
*/
var
err
error
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
//init hooks
AddAPPStartHook
(
registerMime
)
AddAPPStartHook
(
registerMime
)
...
@@ -95,7 +85,7 @@ func initBeforeHTTPRun() {
...
@@ -95,7 +85,7 @@ func initBeforeHTTPRun() {
AddAPPStartHook
(
registerAdmin
)
AddAPPStartHook
(
registerAdmin
)
for
_
,
hk
:=
range
hooks
{
for
_
,
hk
:=
range
hooks
{
if
err
:
=
hk
();
err
!=
nil
{
if
err
=
hk
();
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
}
}
...
...
config.go
View file @
d9e6250d
...
@@ -19,6 +19,7 @@ import (
...
@@ -19,6 +19,7 @@ import (
"os"
"os"
"path/filepath"
"path/filepath"
"strings"
"strings"
"fmt"
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/session"
"github.com/astaxie/beego/session"
...
@@ -103,14 +104,15 @@ var (
...
@@ -103,14 +104,15 @@ var (
BConfig
*
Config
BConfig
*
Config
// AppConfig is the instance of Config, store the config information from file
// AppConfig is the instance of Config, store the config information from file
AppConfig
*
beegoAppConfig
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 stores template caching
TemplateCache
map
[
string
]
*
template
.
Template
TemplateCache
map
[
string
]
*
template
.
Template
// GlobalSessions is the instance for the session manager
// GlobalSessions is the instance for the session manager
GlobalSessions
*
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
()
{
func
init
()
{
...
@@ -173,22 +175,26 @@ func init() {
...
@@ -173,22 +175,26 @@ func init() {
Outputs
:
map
[
string
]
string
{
"console"
:
""
},
Outputs
:
map
[
string
]
string
{
"console"
:
""
},
},
},
}
}
ParseConfig
()
}
// ParseConfig parsed default config file.
AppConfigPath
=
getDefaultAppConfigPath
()
// 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
)
{
if
!
utils
.
FileExists
(
AppConfigPath
)
{
AppConfig
=
&
beegoAppConfig
{
config
.
NewFakeConfig
()}
AppConfig
=
&
beegoAppConfig
{
config
.
NewFakeConfig
()}
return
return
}
}
}
AppConfig
,
err
=
newAppConfig
(
AppConfigProvider
,
AppConfigPath
)
parseConfig
(
AppConfigPath
)
}
func
getDefaultAppConfigPath
()
string
{
// default config path
AppPath
,
_
:=
filepath
.
Abs
(
filepath
.
Dir
(
os
.
Args
[
0
]))
return
filepath
.
Join
(
AppPath
,
"conf"
,
"app.conf"
)
}
// now only support ini, next will support json.
func
parseConfig
(
appConfigPath
string
)
(
err
error
)
{
AppConfig
,
err
=
newAppConfig
(
AppConfigProvider
,
appConfigPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -242,6 +248,8 @@ func ParseConfig() (err error) {
...
@@ -242,6 +248,8 @@ func ParseConfig() (err error) {
BConfig
.
WebConfig
.
Session
.
SessionCookieLifeTime
=
AppConfig
.
DefaultInt
(
"SessionCookieLifeTime"
,
BConfig
.
WebConfig
.
Session
.
SessionCookieLifeTime
)
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
.
SessionAutoSetCookie
=
AppConfig
.
DefaultBool
(
"SessionAutoSetCookie"
,
BConfig
.
WebConfig
.
Session
.
SessionAutoSetCookie
)
BConfig
.
WebConfig
.
Session
.
SessionDomain
=
AppConfig
.
DefaultString
(
"SessionDomain"
,
BConfig
.
WebConfig
.
Session
.
SessionDomain
)
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
!=
""
{
if
sd
:=
AppConfig
.
String
(
"StaticDir"
);
sd
!=
""
{
for
k
:=
range
BConfig
.
WebConfig
.
StaticDir
{
for
k
:=
range
BConfig
.
WebConfig
.
StaticDir
{
...
@@ -274,7 +282,45 @@ func ParseConfig() (err error) {
...
@@ -274,7 +282,45 @@ func ParseConfig() (err error) {
BConfig
.
WebConfig
.
StaticExtensionsToGzip
=
fileExts
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
return
nil
}
AppConfigPath
=
absConfigPath
AppConfigProvider
=
adapterName
return
parseConfig
(
AppConfigPath
)
}
}
type
beegoAppConfig
struct
{
type
beegoAppConfig
struct
{
...
...
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