package data import json "github.com/json-iterator/go" type HeroGeneral struct { Id int `json:"id"` HeroId int `json:"hero_id"` NeedHeroes []int `json:"need_heroes"` AttrType1 int `json:"attr_type1"` AttrValue1 int `json:"attr_value1"` AttrType2 int `json:"attr_type2"` AttrValue2 int `json:"attr_value2"` AttrType3 int `json:"attr_type3"` AttrValue3 int `json:"attr_value3"` } type HeroGeneralTable struct { l []*HeroGeneral m1 map[int]*HeroGeneral m2 map[int][]*HeroGeneral } func (this *HeroGeneralTable) load(buf []byte) error { var err = json.Unmarshal(buf, &this.l) if err != nil { return err } this.m1 = make(map[int]*HeroGeneral) this.m2 = make(map[int][]*HeroGeneral) for i := range this.l { this.m1[this.l[i].Id] = this.l[i] this.m2[this.l[i].HeroId] = append(this.m2[this.l[i].HeroId], this.l[i]) } return nil } func (this *HeroGeneralTable) Find1(heroId int) *HeroGeneral { return this.m1[heroId] } func (this *HeroGeneralTable) Find2(heroId int) []*HeroGeneral { return this.m2[heroId] }