Ejemplo n.º 1
0
func (d *diffDownload) downloadState(sequence int32) (*state.DiffState, error) {
	dest := path.Join(d.dest, diffPath(sequence))
	err := os.MkdirAll(path.Dir(dest), 0755)
	if err != nil {
		return nil, err
	}

	resp, err := http.Get(d.url + diffPath(sequence) + ".state.txt")
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		return nil, errors.New(fmt.Sprintf("invalid repsonse: %v", resp))
	}

	buf := &bytes.Buffer{}
	_, err = io.Copy(buf, resp.Body)
	if err != nil {
		return nil, err
	}

	err = ioutil.WriteFile(dest+".state.txt", buf.Bytes(), 0644)
	if err != nil {
		return nil, err
	}

	reader := bytes.NewReader(buf.Bytes())
	return state.Parse(reader)
}
Ejemplo n.º 2
0
func (d *diffDownload) currentState() (*state.DiffState, error) {
	resp, err := http.Get(d.url + "state.txt")
	if err != nil {
		return nil, err
	}
	if resp.StatusCode != 200 {
		return nil, errors.New(fmt.Sprintf("invalid repsonse: %v", resp))
	}
	defer resp.Body.Close()
	return state.Parse(resp.Body)
}