1 回答

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個贊
mgo 不是 ORM 或驗(yàn)證工具。mgo 只是 MongoDB 的一個接口。
自己做驗(yàn)證也不錯。
type CompanyType int
const (
CompanyA CompanyType = iota // this is the default
CompanyB CompanyType
CompanyC CompanyType
)
type Company struct {
Name string
CompanyType string
}
func (c Company) Valid() bool {
if c.Name == "" {
return false
}
// If it's a user input, you'd want to validate CompanyType's underlying
// integer isn't out of the enum's range.
if c.CompanyType < CompanyA || c.CompanyType > CompanyB {
return false
}
return true
}
檢查這個出了更多關(guān)于圍棋枚舉。
- 1 回答
- 0 關(guān)注
- 170 瀏覽
添加回答
舉報(bào)