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
f7690161
Commit
f7690161
authored
Jan 27, 2016
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1632 from youngsterxyf/config-logic
Config logic
parents
4ce094a2
31ef4ae5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
42 deletions
+72
-42
admin.go
admin.go
+2
-2
beego.go
beego.go
+1
-17
config.go
config.go
+65
-22
log.go
logs/log.go
+1
-0
staticfile_test.go
staticfile_test.go
+3
-1
No files found.
admin.go
View file @
f7690161
...
...
@@ -90,8 +90,8 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
switch
command
{
case
"conf"
:
m
:=
make
(
map
[
string
]
interface
{})
m
[
"AppConfigPath"
]
=
A
ppConfigPath
m
[
"AppConfigProvider"
]
=
A
ppConfigProvider
m
[
"AppConfigPath"
]
=
a
ppConfigPath
m
[
"AppConfigProvider"
]
=
a
ppConfigProvider
m
[
"BConfig.AppName"
]
=
BConfig
.
AppName
m
[
"BConfig.RunMode"
]
=
BConfig
.
RunMode
m
[
"BConfig.RouterCaseSensitive"
]
=
BConfig
.
RouterCaseSensitive
...
...
beego.go
View file @
f7690161
...
...
@@ -15,7 +15,6 @@
package
beego
import
(
"fmt"
"os"
"path/filepath"
"strconv"
...
...
@@ -68,21 +67,6 @@ func Run(params ...string) {
}
func
initBeforeHTTPRun
()
{
// if AppConfigPath is setted or conf/app.conf exist
err
:=
ParseConfig
()
if
err
!=
nil
{
panic
(
err
)
}
//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
)
AddAPPStartHook
(
registerDefaultErrorHandler
)
...
...
@@ -101,7 +85,7 @@ func initBeforeHTTPRun() {
// TestBeegoInit is for test package init
func
TestBeegoInit
(
ap
string
)
{
os
.
Setenv
(
"BEEGO_RUNMODE"
,
"test"
)
A
ppConfigPath
=
filepath
.
Join
(
ap
,
"conf"
,
"app.conf"
)
a
ppConfigPath
=
filepath
.
Join
(
ap
,
"conf"
,
"app.conf"
)
os
.
Chdir
(
ap
)
initBeforeHTTPRun
()
}
config.go
View file @
f7690161
...
...
@@ -19,6 +19,7 @@ import (
"os"
"path/filepath"
"strings"
"fmt"
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/session"
...
...
@@ -105,16 +106,16 @@ var (
AppConfig
*
beegoAppConfig
// AppPath is the absolute path to the app
AppPath
string
// 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
workPath
string
// appConfigPath is the path to the config files
appConfigPath
string
// appConfigProvider is the provider for the config, default is ini
appConfigProvider
=
"ini"
)
func
init
()
{
...
...
@@ -122,6 +123,10 @@ func init() {
workPath
,
_
=
os
.
Getwd
()
workPath
,
_
=
filepath
.
Abs
(
workPath
)
if
workPath
!=
AppPath
{
os
.
Chdir
(
AppPath
)
}
BConfig
=
&
Config
{
AppName
:
"beego"
,
RunMode
:
DEV
,
...
...
@@ -181,26 +186,19 @@ func init() {
Outputs
:
map
[
string
]
string
{
"console"
:
""
},
},
}
ParseConfig
()
}
// ParseConfig parsed default config file.
// now only support ini, next will support json.
func
ParseConfig
()
(
err
error
)
{
if
AppConfigPath
==
""
{
// initialize default configurations
AppConfigPath
=
filepath
.
Join
(
AppPath
,
"conf"
,
"app.conf"
)
if
!
utils
.
FileExists
(
AppConfigPath
)
{
AppConfig
=
&
beegoAppConfig
{
config
.
NewFakeConfig
()}
return
}
appConfigPath
=
filepath
.
Join
(
AppPath
,
"conf"
,
"app.conf"
)
if
!
utils
.
FileExists
(
appConfigPath
)
{
AppConfig
=
&
beegoAppConfig
{
config
.
NewFakeConfig
()}
return
}
if
workPath
!=
AppPath
{
os
.
Chdir
(
AppPath
)
}
parseConfig
(
appConfigPath
)
}
AppConfig
,
err
=
newAppConfig
(
AppConfigProvider
,
AppConfigPath
)
// now only support ini, next will support json.
func
parseConfig
(
appConfigPath
string
)
(
err
error
)
{
AppConfig
,
err
=
newAppConfig
(
appConfigProvider
,
appConfigPath
)
if
err
!=
nil
{
return
err
}
...
...
@@ -254,6 +252,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
{
...
...
@@ -286,15 +286,58 @@ 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
(
adapterName
,
configPath
string
)
error
{
absConfigPath
,
err
:=
filepath
.
Abs
(
configPath
)
if
err
!=
nil
{
return
err
}
if
!
utils
.
FileExists
(
absConfigPath
)
{
return
fmt
.
Errorf
(
"the target config file: %s don't exist!"
,
configPath
)
}
if
absConfigPath
==
appConfigPath
{
return
nil
}
appConfigPath
=
absConfigPath
appConfigProvider
=
adapterName
return
parseConfig
(
appConfigPath
)
}
type
beegoAppConfig
struct
{
innerConfig
config
.
Configer
}
func
newAppConfig
(
AppConfigProvider
,
A
ppConfigPath
string
)
(
*
beegoAppConfig
,
error
)
{
ac
,
err
:=
config
.
NewConfig
(
AppConfigProvider
,
A
ppConfigPath
)
func
newAppConfig
(
appConfigProvider
,
a
ppConfigPath
string
)
(
*
beegoAppConfig
,
error
)
{
ac
,
err
:=
config
.
NewConfig
(
appConfigProvider
,
a
ppConfigPath
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
logs/log.go
View file @
f7690161
...
...
@@ -365,6 +365,7 @@ func (bl *BeeLogger) Close() {
l
.
Flush
()
l
.
Destroy
()
}
bl
.
outputs
=
nil
}
func
formatLogTime
(
when
time
.
Time
)
string
{
...
...
staticfile_test.go
View file @
f7690161
...
...
@@ -8,9 +8,11 @@ import (
"io/ioutil"
"os"
"testing"
"path/filepath"
)
const
licenseFile
=
"./LICENSE"
var
currentWorkDir
,
_
=
os
.
Getwd
()
var
licenseFile
=
filepath
.
Join
(
currentWorkDir
,
"LICENSE"
)
func
testOpenFile
(
encoding
string
,
content
[]
byte
,
t
*
testing
.
T
)
{
fi
,
_
:=
os
.
Stat
(
licenseFile
)
...
...
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