我正在尝试访问Features
。使用以下条件的结构的Id
。
Record, _ := s.Dao.GetFeatPlansById(QueryId)
if Record.Features.Id == 0 { // <-- error here
// Do something
}
Record
具有以下结构type Record struct {
Id int
Name string
Features []*Feature
}
// The following Feature struct is located on another file
type Feature struct {
Id int
Name string
}
但是,golang返回以下错误消息Record.Features.Id undefined (type []*dao.Feature has no field or method Id) compiler
我们如何访问Features
。 Id
?
最佳答案
我会根据收到的反馈回答我的问题。
我要做的是访问 slice ,并从我需要的内容中获取第一个索引。
feature := Record.Features[0]
if feature.Id == 0 {
Record.Features = nil
}
关于go - golang类型[] dao.Record没有字段或方法ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63957931/