mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 08:30:54 +00:00
fix bug of getting int error
This commit is contained in:
parent
9fda81b7f3
commit
50f71a8a21
@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@ -91,13 +92,7 @@ func (c *JSONConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
|||||||
// Int returns the integer value for a given key.
|
// Int returns the integer value for a given key.
|
||||||
func (c *JSONConfigContainer) Int(key string) (int, error) {
|
func (c *JSONConfigContainer) Int(key string) (int, error) {
|
||||||
val := c.getData(key)
|
val := c.getData(key)
|
||||||
if val != nil {
|
return strconv.Atoi(val.(string))
|
||||||
if v, ok := val.(float64); ok {
|
|
||||||
return int(v), nil
|
|
||||||
}
|
|
||||||
return 0, errors.New("not int value")
|
|
||||||
}
|
|
||||||
return 0, errors.New("not exist key:" + key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultInt returns the integer value for a given key.
|
// DefaultInt returns the integer value for a given key.
|
||||||
|
Loading…
Reference in New Issue
Block a user