0
我想迭代一个接口片来找到我的特定结构的id并更改属性。Go lang界面
type A struct {
ID ID
Steps []Step
}
type Step interface{}
type B struct {
ID ID
}
type C struct {
ID ID
}
func (s *A) findStepByID(id ID) (Step, error) {
for index, step := range s.Steps {
switch stepType := step.(type) {
case A:
if stepType.ID == id {
return step, nil
}
case B:
if stepType.ID == id {
return step, nil
}
default:
return nil, errors.New("no step found")
}
}
return nil, errors.New("no step found")
}
当我发现我的例如B
结构,然后我将设置B.ID = xy
这里有什么问题? –
问题是什么? – I159
如何做到这一点,我得到的错误,步骤是一个没有方法的接口 – Fesco