Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
3b99f37a
authored
2014-01-11 14:28:11 +0800
by
slene
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add a empty fake config Initialize AppConfig to avoid nil pointer runtime error.
1 parent
e8f5c104
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
1 deletions
beego.go
config.go
config/fake.go
beego.go
View file @
3b99f37
...
...
@@ -192,7 +192,7 @@ func Run() {
}
if
SessionOn
{
var
err
error
var
err
error
sessionConfig
:=
AppConfig
.
String
(
"sessionConfig"
)
if
sessionConfig
==
""
{
sessionConfig
=
`{"cookieName":"`
+
SessionName
+
`",`
+
...
...
config.go
View file @
3b99f37
...
...
@@ -141,6 +141,7 @@ func init() {
func
ParseConfig
()
(
err
error
)
{
AppConfig
,
err
=
config
.
NewConfig
(
"ini"
,
AppConfigPath
)
if
err
!=
nil
{
AppConfig
=
config
.
NewFakeConfig
()
return
err
}
else
{
HttpAddr
=
AppConfig
.
String
(
"HttpAddr"
)
...
...
config/fake.go
0 → 100644
View file @
3b99f37
package
config
import
(
"errors"
"strconv"
"strings"
)
type
fakeConfigContainer
struct
{
data
map
[
string
]
string
}
func
(
c
*
fakeConfigContainer
)
getData
(
key
string
)
string
{
key
=
strings
.
ToLower
(
key
)
return
c
.
data
[
key
]
}
func
(
c
*
fakeConfigContainer
)
Set
(
key
,
val
string
)
error
{
key
=
strings
.
ToLower
(
key
)
c
.
data
[
key
]
=
val
return
nil
}
func
(
c
*
fakeConfigContainer
)
String
(
key
string
)
string
{
return
c
.
getData
(
key
)
}
func
(
c
*
fakeConfigContainer
)
Int
(
key
string
)
(
int
,
error
)
{
return
strconv
.
Atoi
(
c
.
getData
(
key
))
}
func
(
c
*
fakeConfigContainer
)
Int64
(
key
string
)
(
int64
,
error
)
{
return
strconv
.
ParseInt
(
c
.
getData
(
key
),
10
,
64
)
}
func
(
c
*
fakeConfigContainer
)
Bool
(
key
string
)
(
bool
,
error
)
{
return
strconv
.
ParseBool
(
c
.
getData
(
key
))
}
func
(
c
*
fakeConfigContainer
)
Float
(
key
string
)
(
float64
,
error
)
{
return
strconv
.
ParseFloat
(
c
.
getData
(
key
),
64
)
}
func
(
c
*
fakeConfigContainer
)
DIY
(
key
string
)
(
interface
{},
error
)
{
key
=
strings
.
ToLower
(
key
)
if
v
,
ok
:=
c
.
data
[
key
];
ok
{
return
v
,
nil
}
return
nil
,
errors
.
New
(
"key not find"
)
}
var
_
ConfigContainer
=
new
(
fakeConfigContainer
)
func
NewFakeConfig
()
ConfigContainer
{
return
&
fakeConfigContainer
{
data
:
make
(
map
[
string
]
string
),
}
}
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment