示例#1
0
文件: path.go 项目: nelsonomuto/slurp
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
}
示例#2
0
文件: http.go 项目: nelsonomuto/slurp
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
}