Esempio n. 1
0
func dirsFromServer(ip string, port int, key string, lastIndexed int64) []interface{} {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println(err)
		}
	}()
	client := &http.Client{}
	req, _ := http.NewRequest("GET", fmt.Sprint("http://", ip, ":", port, "/dirs?last_indexed=", lastIndexed), nil)
	req.Header.Add("AUTH_KEY", key)
	resp, _ := client.Do(req)
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	json, _ := simplejson.NewJson(body)
	dirs := json.MustArray()
	return dirs
}
Esempio n. 2
0
func filePartsFromServer(ip string, port int, key string, filePath string) []interface{} {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println(err)
		}
	}()
	client := &http.Client{}
	req, _ := http.NewRequest("GET", fmt.Sprint("http://", ip, ":", port,
		"/file_parts?file_path=", url.QueryEscape(filePath)), nil)
	req.Header.Add("AUTH_KEY", key)
	resp, _ := client.Do(req)
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	json, _ := simplejson.NewJson(body)
	fileParts := json.MustArray()
	return fileParts
}