Пример #1
0
func main() {
	if len(os.Args) < 3 {
		fmt.Println("format test infile outfile")
		return
	}
	filestr := os.Args[1]
	file, err := os.Open(filestr)
	if err != nil {
		panic(err)
	}
	ofilestr := os.Args[2]
	ofile, err := os.Create(ofilestr)
	defer ofile.Close()
	if err != nil {
		panic(err)
	}
	clt := client.NewClientTee(file, "http://127.0.0.1:8080/hash", ofile)
	clt.Start()
	if err != nil {
		panic(err)
	}
	req, err := http.NewRequest("POST", "http://127.0.0.1:8080/file", clt)
	if err != nil {
		panic(err)
	}
	client := &http.Client{}
	res, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	if res.StatusCode != http.StatusOK {
		err = fmt.Errorf("bad status:%s", res.Status)
		panic(err)
	}
}
Пример #2
0
func postHash(url string, file string) {
	f, err := os.Open(file)
	if err != nil {
		panic(err)
	}
	defer f.Close()
	b := client.NewIdxReader(f)
	req, err := http.NewRequest("POST", url, b)
	if err != nil {
		panic(err)
	}
	client := &http.Client{}
	fmt.Println("debug ")
	res, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	if res.StatusCode != http.StatusOK {
		err = fmt.Errorf("bad status:%s", res.Status)
		return
	}
	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(body))
}