Exemple #1
0
func (f *Repository) Index() (entity.Index, error) {
	resp, err := http.Get(f.remote + "/index.json")
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("Unexpected status code: %d", resp.StatusCode)
	}
	data := struct {
		Commands []struct {
			Name      string   `json:"name"`
			Platforms []string `json:"platform"`
		} `json:"commands"`
	}{}
	decoder := json.NewDecoder(resp.Body)
	err = decoder.Decode(&data)
	if err != nil {
		return nil, err
	}
	indexMap := map[string][]string{}
	for _, command := range data.Commands {
		indexMap[command.Name] = command.Platforms
	}
	return entity.NewIndex(indexMap), nil
}
Exemple #2
0
func (f *FileSystemCacheRepository) loadIndexFromCache(filePath string) (entity.Index, error) {
	file, err := f.loadFromCache(filePath)
	if err != nil {
		return nil, err
	}
	if file == nil {
		return nil, nil
	}
	defer file.Close()
	decoder := json.NewDecoder(file)
	jsonMap := map[string][]string{}
	err = decoder.Decode(&jsonMap)
	if err != nil {
		return nil, err
	}
	return entity.NewIndex(jsonMap), nil
}