What is the idiomatic way to read urls with a file scheme as filenames for ReadFile?
Is there an idiomatic way to read a file from the system, starting from the url (file scheme) and not the path?
I tried this first:
fileUrlStr := "file:///path/to/file.json"
jsonBuffer, _ := ioutil.ReadFile(fileUrlStr)
This is my current (mostly working version), but I am concerned that there are some bugs that I am missing, so I hope there is a more tried and true way to do it:
fileUrlStr := "file:///path/to/file.json"
fileUrl, _ := url.Parse(fileUrlStr)
jsonBuffer, _ := ioutil.ReadFile(fileUrl.Path)
(Bonus if I can support both file:///Users/jdoe/temp.json
, and file:///c:/WINDOWS/clock.json
without adding code paths for them)
+3
source to share
No one has answered this question yet
Check out similar questions: