Пример #1
0
func ListFiles(server string) ([]FileHash, error) {
	jsonBlob, err := util.Get("http://" + server + "/list")
	if err != nil {
		return nil, err
	}
	var ret ListFileResult
	err = json.Unmarshal(jsonBlob, &ret)
	if err != nil {
		return nil, err
	}
	return ret.Files, nil
}
Пример #2
0
func (n *NameServiceProxy) Find(name string) (locations []string) {
	for _, l := range n.Leaders {
		jsonBlob, err := util.Get("http://" + l + "/channel/" + name)
		if err != nil {
			log.Printf("Failed to list from %s:%v", l, err)
		}
		var ret []master.ChannelInformation
		err = json.Unmarshal(jsonBlob, &ret)
		if err != nil {
			fmt.Printf("%s/list%s unmarshal error:%v, json:%s", l, name, err, string(jsonBlob))
			continue
		}
		if len(ret) <= 0 {
			return nil
		}
		for _, rs := range ret {
			locations = append(locations, rs.Location)
		}
	}
	return locations
}