package main import ( "fmt" "net/http" ) func main() { file, err := http.FileSystem.Open("path/to/local/file.txt") if err != nil { panic(err) } defer file.Close() fileInfo, err := file.Stat() if err != nil { panic(err) } fmt.Println(fileInfo.Name()) }
package main import ( "fmt" "net/http" ) func main() { httpClient := http.DefaultClient resp, err := httpClient.Get("https://example.com/myfile.txt") if err != nil { panic(err) } defer resp.Body.Close() file, err := http.FileSystem.Open("https://example.com/myfile.txt") if err != nil { panic(err) } defer file.Close() fileInfo, err := file.Stat() if err != nil { panic(err) } fmt.Println(fileInfo.Name()) }In this example, the net/http FileSystem Open function is used to open a remote file over http and obtain its file info. The HTTP client is initialized with the default HTTP client and the request is made using the Get method. The file is closed using the defer statement.