dsbpaqt61965 2018-11-26 12:07
浏览 117
已采纳

如何用字符串切换大小写

Here is my code:

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")
    }

}

And here is the error that I got :

.\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)

I truly don't understand how it's not working. I'm trying to follow this tutorial

  • 写回答

2条回答 默认 最新

  • duai4379 2018-11-26 12:09
    关注

    Your New function must looks like:

    func New(value string) Etat {
        switch value {
        case "Recette", "Production":
            return Etat{Value :value}
        default:
            panic("unrecognized value")
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?