1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 17:20:50 +00:00

fix bug of getting int error

This commit is contained in:
jianzhiyao 2020-06-02 18:10:17 +08:00
parent 9fda81b7f3
commit 50f71a8a21

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"sync"
)
@ -91,13 +92,7 @@ func (c *JSONConfigContainer) DefaultBool(key string, defaultval bool) bool {
// Int returns the integer value for a given key.
func (c *JSONConfigContainer) Int(key string) (int, error) {
val := c.getData(key)
if val != nil {
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)
return strconv.Atoi(val.(string))
}
// DefaultInt returns the integer value for a given key.