go - 如何检查结构字段值是否存在于另一个结构字段中
问题描述
type Bundle struct {
Name string `bson:"name" json:"name"`
Choices []string `bson:"choices" json:"choices"`
}
type Event struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"_id,omitempty"`
Bundle []Bundle `bson:"bundle" json:"bundle"`
}
type AttendeeBundle struct {
Name string `bson:"name" json:"name"`
Details string `bson:"details" json:"details"`
}
type Attendees struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"_id,omitempty"`
Bundle []AttendeeBundle `bson:"bundle" json:"bundle"`
}
我正在建立一个活动注册平台。活动包含一个 Bundle 字段,与会者可以从中进行选择。例如。各种尺寸或颜色的 T 恤。
因此,在注册时,我想确保与会者从相应的活动中选择正确的捆绑包。
我知道可以为与会者和活动进行迭代,如下所示:
for _ , attendeebundle := range Attendees.Bundle {
for _, eventbundle := range Event.Bundle{
//comparing attendee bundle and event bundle
}
}
}
但是,我认为这太多余了,还有其他更优雅/有效的方法吗?
解决方案
推荐阅读
- java - Is there a way to automatically discover an SQL database on your network?
- python - 如果我使用 keras 方法 Flow_from_firectory,如何在我的数据中执行规范化
- amazon-web-services - AWS EC2:无法通过 docker 使用 letencrypt 和 nginx 访问端口 80 或 443 (https)
- openlayers - OpenLayers 在 [-180] [180] 经度附近的两点之间绘制最短路径
- c# - 列表
Firestore 中的对象转换错误 - css - 如何使用 SQL 变量
- audio - 如何使 PGraphics 充满点(白色等级基于幅度)和不断变化的弧线的纹理?
- java - 无法让 PackageInstaller.uninstall 工作
- node.js - 在nodejs中安装请求后未定义请求
- java - 如何在 IntelliJ 中导入/打开现有的 .java 文件?