1 Star 0 Fork 0

ichub / goconfig

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
BitField.go 792 Bytes
一键复制 编辑 原始数据 按行查看 历史
leijmdas 提交于 2024-03-25 15:25 . add
package basemodel
import (
"database/sql/driver"
"fmt"
"strconv"
)
type BitField bool
func (t *BitField) MarshalJSON() ([]byte, error) {
var value bool
if *t {
value = true
} else {
value = false
}
return []byte(strconv.FormatBool(value)), nil
}
func (t *BitField) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
return nil
}
b, _ := strconv.ParseBool(string(data))
if b {
*t = true
} else {
*t = false
}
return nil
}
func (t *BitField) Value() (driver.Value, error) {
if *t {
return true, nil
}
return false, nil
}
func (t *BitField) Scan(v interface{}) error {
value, ok := v.([]byte)
if ok {
if value[0] == 0x01 {
*t = true
} else {
*t = false
}
return nil
}
return fmt.Errorf("can not convert %v to timestamp", v)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ichub/goconfig.git
git@gitee.com:ichub/goconfig.git
ichub
goconfig
goconfig
v1.0.405

搜索帮助

344bd9b3 5694891 D2dac590 5694891