// loadProfiles loads hotel profiles from a JSON file. func loadProfiles(path string) map[string]*profile.Hotel { file := data.MustAsset(path) // unmarshal json profiles hotels := []*profile.Hotel{} if err := json.Unmarshal(file, &hotels); err != nil { log.Fatalf("Failed to load json: %v", err) } profiles := make(map[string]*profile.Hotel) for _, hotel := range hotels { profiles[hotel.Id] = hotel } return profiles }
// loadCustomers loads customers from a JSON file. func loadCustomerData(path string) map[string]*auth.Customer { file := data.MustAsset(path) customers := []*auth.Customer{} // unmarshal JSON if err := json.Unmarshal(file, &customers); err != nil { log.Fatalf("Failed to unmarshal json: %v", err) } // create customer lookup map cache := make(map[string]*auth.Customer) for _, c := range customers { cache[c.AuthToken] = c } return cache }
// newGeoIndex returns a geo index with points loaded func newGeoIndex(path string) *geoindex.ClusteringIndex { file := data.MustAsset(path) // unmarshal json points var points []*point if err := json.Unmarshal(file, &points); err != nil { log.Fatalf("Failed to load hotels: %v", err) } // add points to index index := geoindex.NewClusteringIndex() for _, point := range points { index.Add(point) } return index }
// loadRates loads rate codes from JSON file. func loadRateTable(path string) map[stay]*rate.RatePlan { file := data.MustAsset("data/rates.json") rates := []*rate.RatePlan{} if err := json.Unmarshal(file, &rates); err != nil { log.Fatalf("Failed to load json: %v", err) } rateTable := make(map[stay]*rate.RatePlan) for _, ratePlan := range rates { stay := stay{ HotelID: ratePlan.HotelId, InDate: ratePlan.InDate, OutDate: ratePlan.OutDate, } rateTable[stay] = ratePlan } return rateTable }