// GetProviders returns an array of the first 10 Providers. // FIXME support different result counts func GetProviders(db *godis.Client) []Resource { var providers []Resource // fetch the Providers r, err := db.Lrange("idx:Provider", 0, 10) if err != nil { log.Fatal("Could not get providers.") } // conver the Reply into a []string of "Id|Label" representations s := r.StringArray() // loop through all results, creating resources for i := 0; i < len(s); i++ { // split the "Id|Label" vals := strings.SplitN(s[i], "|", 2) if len(vals) != 2 { log.Fatalf("For some reason, the index was improperly formatted: %s", s[i]) } // build the Provider var p Provider p.Identifier = vals[0] p.Name = vals[1] // create a resource from the provider and add it to the array to return providers = append(providers, NewResource(&p)) } // return the array of providers return providers }