package data import json "github.com/json-iterator/go" type HeroBook 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 HeroBookTable struct { l []*HeroBook m1 map[int]*HeroBook m2 map[int][]*HeroBook } func (this *HeroBookTable) load(buf []byte) error { var err = json.Unmarshal(buf, &this.l) if err != nil { return err } this.m1 = make(map[int]*HeroBook) this.m2 = make(map[int][]*HeroBook) 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 *HeroBookTable) List() []*HeroBook { return this.l } //func (this *HeroBookTable) Get(i int) *HeroBook { // return this.l[i] //} func (this *HeroBookTable) Find1(id int) *HeroBook { return this.m1[id] } func (this *HeroBookTable) Find2(heroId int) []*HeroBook { return this.m2[heroId] }