我有Product带字段的模型Type。
像这样的东西:
type ProductType string
var (
PtRouteTransportation ProductType = "ProductRT"
PtOnDemandTransportation ProductType = "ProductDT"
PtExcursion ProductType = "ProductEX"
PtTicket ProductType = "ProductTK"
PtQuote ProductType = "ProductQT"
PtGood ProductType = "ProductGD"
)
type Product struct {
...
Type ProductType
...
}
在Create函数中,我有type表单参数:
type := req.Form.Get("type")
问题:如何检查是否type有效?
最简单的方法是:
if type != PtRouteTransportation && type != PtOnDemandTransportation && ...
但是如果Product有 100 种类型,我该怎么办?
如何以这种go方式做到这一点?
慕仙森
相关分类