Exemple #1
0
func ReplaceExt(f slurp.File, Old string, New string) (slurp.File, error) {

	path := strings.TrimSuffix(f.Path, Old) + New
	f.Path = path
	f.FileInfo.SetName(path)

	return f, nil
}
Exemple #2
0
func Get(url string) (slurp.File, error) {

	file := slurp.File{Cwd: "", Dir: ""}

	resp, err := http.Get(url)
	if err != nil {
		return file, err
	}

	if resp.StatusCode < 200 || resp.StatusCode > 399 {
		return file, fmt.Errorf("%s (%s)", resp.Status, url)
	}

	file.Reader = resp.Body

	name := name(url, resp)

	file.FileInfo.SetName(name)
	file.Path = name
	file.FileInfo.SetSize(resp.ContentLength)

	return file, nil
}