1 Star 0 Fork 1

go-genie/sqlx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bool.go 948 Bytes
一键复制 编辑 原始数据 按行查看 历史
文兄 提交于 2025-05-27 09:19 +08:00 . init
package datatypes
import (
"encoding/json"
)
// openapi:type boolean
type Bool int
const (
BOOL_UNKNOWN Bool = iota
BOOL_TRUE // true
BOOL_FALSE // false
)
var _ interface {
json.Unmarshaler
json.Marshaler
} = (*Bool)(nil)
func (v Bool) True() bool {
return v == BOOL_TRUE
}
func (v Bool) False() bool {
return v == BOOL_FALSE
}
func (Bool) OpenAPISchemaType() []string {
return []string{"boolean"}
}
func (v Bool) MarshalText() ([]byte, error) {
switch v {
case BOOL_FALSE:
return []byte("false"), nil
case BOOL_TRUE:
return []byte("true"), nil
default:
return []byte("null"), nil
}
}
func (v *Bool) UnmarshalText(data []byte) (err error) {
switch string(data) {
case "false":
*v = BOOL_FALSE
case "true":
*v = BOOL_TRUE
}
return
}
func (v Bool) MarshalJSON() ([]byte, error) {
return v.MarshalText()
}
func (v *Bool) UnmarshalJSON(data []byte) (err error) {
return v.UnmarshalText(data)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/go-genie/sqlx.git
git@gitee.com:go-genie/sqlx.git
go-genie
sqlx
sqlx
v1.1.3

搜索帮助