Add StringCmd.Bool()

This commit is contained in:
Shuo 2021-03-17 15:50:02 +08:00 committed by GitHub
parent 7ba7ac4a7f
commit 785fa3295c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -710,6 +710,13 @@ func (cmd *StringCmd) Bytes() ([]byte, error) {
return util.StringToBytes(cmd.val), cmd.err return util.StringToBytes(cmd.val), cmd.err
} }
func (cmd *StringCmd) Bool() (bool, error) {
if cmd.err != nil {
return false, cmd.err
}
return strconv.ParseBool(cmd.val)
}
func (cmd *StringCmd) Int() (int, error) { func (cmd *StringCmd) Int() (int, error) {
if cmd.err != nil { if cmd.err != nil {
return 0, cmd.err return 0, cmd.err