2016-12-01 01:53
浏览 864


I need to initialize the following data structure which will store a json. The Attack_plans will hold multiple plans and if I loop through the GeneratePlan struct, I need all the plans that were stored.

type GeneratePlan struct {
    Mode         string `json:"mode"`
    Name         string `json:"name"`
    Schema       string `json:"schema"`
    Version      string `json:"version"`
    Attack_plans []struct {
        Attack_plan *Attack_plan `json:"attack-plan"`
    } `json:"attack-plans"`
type Attack_plan struct {
    Attack_resources []struct {
        Attack_resource *Attack_resource `json:"attack-resource"`
    } `json:"attack-resources"`

Can anyone please suggest something? If the data structure needs to be simplified before initializing it, then please suggest that as well. I am very new to golang so please ignore the best practices to follow. Any help is appreciated. Thanks!

图片转代码服务由CSDN问答提供 功能建议

我需要初始化以下将存储json的数据结构。 Attack_plans将包含多个计划,如果我遍历GeneratePlan结构,则需要存储的所有计划。

  type GeneratePlan结构{
模式字符串`json:“ 模式“`
名称字符串`json:” name“`
模式字符串`json:” schema“`
版本字符串`json:” version“`
 Attack_plans [] struct {
 Attack_plan * Attack_plan`json  :“”攻击计划“`
type Attack_plan struct {
 Attack_resources [] struct {
 Attack_resource * Attack_resource`json:” attack-resource“`

有人可以提出建议吗? 如果在初始化之前需要简化数据结构,则也建议这样做。 我刚接触过golang,因此请忽略要遵循的最佳做法。 任何帮助表示赞赏。 谢谢!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新