这是我的代码:
type Etat struct {
gorm.Model
Value string `form:"value"`
}
func New(value string) Etat {
switch value {
case 'Recette':
return Etat{Value :value}
case 'Production':
return Etat{Value :value}
default:
panic("unrecognized value")
}
}
这是我得到的错误:
.\MicroConf.go:23:2: invalid case '\u0000' in switch on value (mismatched types rune and string)
.\MicroConf.go:23:7: invalid character literal (more than one character)
.\MicroConf.go:25:2: invalid case '\u0000' in switch on value (mismatched types rune and string)
.\MicroConf.go:25:2: duplicate case '\u0000' (value 0) in switch
previous case at .\MicroConf.go:23:7
.\MicroConf.go:25:7: invalid character literal (more than one character)
我真的不明白它是如何工作的。我正在尝试遵循此tutorial
答案 0 :(得分:2)
您的新功能必须类似于:
func New(value string) Etat {
switch value {
case "Recette", "Production":
return Etat{Value :value}
default:
panic("unrecognized value")
}
}
答案 1 :(得分:2)
使用双引号代替单引号,以防万一。
case "Recette":
instead of
case 'Recette':
顺便说一句,最好将函数名称从New()更改为其他名称