1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-06 02:00:18 +00:00

Support Parse Bool with more diffrent values

ParseBool returns the boolean value represented by the string.
It accepts 1, 1.0, t, T, TRUE, true, True, YES, yes, Yes,Y, y, ON, on,
On,
 0, 0.0, f, F, FALSE, false, False, NO, no, No, N,n, OFF, off, Off.
Any other value returns an error.
This commit is contained in:
ysqi
2016-01-23 11:02:40 +08:00
parent af346e871b
commit be544f963e
8 changed files with 202 additions and 118 deletions

View File

@ -17,6 +17,7 @@ package config
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
@ -70,12 +71,9 @@ type JSONConfigContainer struct {
func (c *JSONConfigContainer) Bool(key string) (bool, error) {
val := c.getData(key)
if val != nil {
if v, ok := val.(bool); ok {
return v, nil
}
return false, errors.New("not bool value")
return ParseBool(val)
}
return false, errors.New("not exist key:" + key)
return false, fmt.Errorf("not exist key: %q", key)
}
// DefaultBool return the bool value if has no error