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
ca1fd96e
Commit
ca1fd96e
authored
Jul 10, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #687 from fuxiaohei/develop
code style simplify
parents
19c3a5b4
007db805
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
32 deletions
+21
-32
cache.go
cache/cache.go
+6
-5
conv.go
cache/conv.go
+15
-27
No files found.
cache/cache.go
View file @
ca1fd96e
...
@@ -51,7 +51,7 @@ func Register(name string, adapter Cache) {
...
@@ -51,7 +51,7 @@ func Register(name string, adapter Cache) {
if
adapter
==
nil
{
if
adapter
==
nil
{
panic
(
"cache: Register adapter is nil"
)
panic
(
"cache: Register adapter is nil"
)
}
}
if
_
,
dup
:=
adapters
[
name
];
dup
{
if
_
,
ok
:=
adapters
[
name
];
ok
{
panic
(
"cache: Register called twice for adapter "
+
name
)
panic
(
"cache: Register called twice for adapter "
+
name
)
}
}
adapters
[
name
]
=
adapter
adapters
[
name
]
=
adapter
...
@@ -60,14 +60,15 @@ func Register(name string, adapter Cache) {
...
@@ -60,14 +60,15 @@ func Register(name string, adapter Cache) {
// Create a new cache driver by adapter name and config string.
// Create a new cache driver by adapter name and config string.
// config need to be correct JSON as string: {"interval":360}.
// config need to be correct JSON as string: {"interval":360}.
// it will start gc automatically.
// it will start gc automatically.
func
NewCache
(
adapterName
,
config
string
)
(
Cache
,
error
)
{
func
NewCache
(
adapterName
,
config
string
)
(
adapter
Cache
,
e
error
)
{
adapter
,
ok
:=
adapters
[
adapterName
]
adapter
,
ok
:=
adapters
[
adapterName
]
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"cache: unknown adapter name %q (forgot to import?)"
,
adapterName
)
e
=
fmt
.
Errorf
(
"cache: unknown adapter name %q (forgot to import?)"
,
adapterName
)
return
}
}
err
:=
adapter
.
StartAndGC
(
config
)
err
:=
adapter
.
StartAndGC
(
config
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
adapter
=
nil
}
}
return
adapter
,
nil
return
}
}
cache/conv.go
View file @
ca1fd96e
...
@@ -22,12 +22,11 @@ func GetString(v interface{}) string {
...
@@ -22,12 +22,11 @@ func GetString(v interface{}) string {
case
[]
byte
:
case
[]
byte
:
return
string
(
result
)
return
string
(
result
)
default
:
default
:
if
v
==
nil
{
if
v
!=
nil
{
return
""
}
else
{
return
fmt
.
Sprintf
(
"%v"
,
result
)
return
fmt
.
Sprintf
(
"%v"
,
result
)
}
}
}
}
return
""
}
}
// convert interface to int.
// convert interface to int.
...
@@ -40,12 +39,9 @@ func GetInt(v interface{}) int {
...
@@ -40,12 +39,9 @@ func GetInt(v interface{}) int {
case
int64
:
case
int64
:
return
int
(
result
)
return
int
(
result
)
default
:
default
:
d
:=
GetString
(
v
)
if
d
:=
GetString
(
v
);
d
!=
""
{
if
d
!=
""
{
value
,
_
:=
strconv
.
Atoi
(
d
)
value
,
err
:=
strconv
.
Atoi
(
d
)
return
value
if
err
==
nil
{
return
value
}
}
}
}
}
return
0
return
0
...
@@ -61,12 +57,10 @@ func GetInt64(v interface{}) int64 {
...
@@ -61,12 +57,10 @@ func GetInt64(v interface{}) int64 {
case
int64
:
case
int64
:
return
result
return
result
default
:
default
:
d
:=
GetString
(
v
)
if
d
!=
""
{
if
d
:=
GetString
(
v
);
d
!=
""
{
result
,
err
:=
strconv
.
ParseInt
(
d
,
10
,
64
)
value
,
_
:=
strconv
.
ParseInt
(
d
,
10
,
64
)
if
err
==
nil
{
return
value
return
result
}
}
}
}
}
return
0
return
0
...
@@ -78,12 +72,9 @@ func GetFloat64(v interface{}) float64 {
...
@@ -78,12 +72,9 @@ func GetFloat64(v interface{}) float64 {
case
float64
:
case
float64
:
return
result
return
result
default
:
default
:
d
:=
GetString
(
v
)
if
d
:=
GetString
(
v
);
d
!=
""
{
if
d
!=
""
{
value
,
_
:=
strconv
.
ParseFloat
(
d
,
64
)
value
,
err
:=
strconv
.
ParseFloat
(
d
,
64
)
return
value
if
err
==
nil
{
return
value
}
}
}
}
}
return
0
return
0
...
@@ -95,12 +86,9 @@ func GetBool(v interface{}) bool {
...
@@ -95,12 +86,9 @@ func GetBool(v interface{}) bool {
case
bool
:
case
bool
:
return
result
return
result
default
:
default
:
d
:=
GetString
(
v
)
if
d
:=
GetString
(
v
);
d
!=
""
{
if
d
!=
""
{
value
,
_
:=
strconv
.
ParseBool
(
d
)
result
,
err
:=
strconv
.
ParseBool
(
d
)
return
value
if
err
==
nil
{
return
result
}
}
}
}
}
return
false
return
false
...
...
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