go - golang类型[] dao.Record没有字段或方法ID

标签 go struct

我正在尝试访问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
我们如何访问FeaturesId

最佳答案

我会根据收到的反馈回答我的问题。
我要做的是访问 slice ,并从我需要的内容中获取第一个索引。

feature := Record.Features[0]
    if feature.Id == 0 {
        Record.Features = nil
    }

关于go - golang类型[] dao.Record没有字段或方法ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63957931/

相关文章:

go - 所有可能的 GOOS 值?

algorithm - D. B. Johnson 的 "elementary circuits"算法应该产生不同的结果吗?

c++ - 处理结构数组 : all in one place vs splitting vs arrays within structs 的正确方法

go - 为什么binary.Read()对struct不起作用?

api - 如何使用相同的端口地址和不同的句柄模式同时提供网页和 API 路由

mongodb - 复合文字使用无键字段

go - 检查用户输入的字符串

c++ - 指针类 C++

C 结构初始化 : strange way

c++ - 无法从不同的类中检索结构内部的值(返回 0)