повтор кода слишком много, я sh это более упростить - PullRequest
0 голосов
/ 29 апреля 2020

текущий код

switch configType {
    case 1:
        //some struct
        list := AFormat{}

        //this is find result from gorm
        gorm.Find(&list)
        //result
        self.Output(200, "success", list)

    case 2:  
        //some struct
        list := BFormat{}

        //this is find result from gorm
        gorm.Find(&list)
        self.Output(200, "success", list)

}

i wi sh только одно возвращение, я пытаюсь сделать это так

var list interface{}
switch configType {
    case 1:
         //some struct
        list = AFormat{}
        //this is find result from gorm

        gorm.Find(&list)

    case 2:
         //some struct
        list = BFormat{}
        //this is find result from gorm

        gorm.Find(&list)

}
self.Output(200, "success", list)

, но есть ошибка: неподдерживаемый пункт назначения, должен быть фрагмент или структура как поменять этот код на право

...