fix bug of getting int error

This commit is contained in:
jianzhiyao 2020-06-02 18:10:17 +08:00
parent 9fda81b7f3
commit 50f71a8a21
1 changed files with 2 additions and 7 deletions

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.