We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go version
$ go version go version go1.16 windows/amd64
Yes, it is introduced by the latest release, which introduced embed
embed
go env
$ go env set GOARCH=amd64 set GOHOSTARCH=amd64 set GOHOSTOS=windows
With a file at ./assets/test.json:
./assets/test.json
package main import ( "embed" "fmt" "io/ioutil" "path/filepath" ) //go:embed assets/* var assets embed.FS func main() { path := filepath.Join("assets", "test.json") data, err := ioutil.ReadFile(path) if err != nil { fmt.Println("error reading real file:", err) return } fmt.Println(string(data)) data, err = assets.ReadFile(path) if err != nil { fmt.Println("error reading embedded file:", err) return } fmt.Println(string(data)) }
$ go run main.go {"hello":"world"} {"hello":"world"}
$ go run main.go {"hello":"world"} error reading embedded file: open assets\test.json: file does not exist
We can infer this is a path problem because if we instead do:
path = strings.ReplaceAll(path, "\\", "/") data, err = assets.ReadFile(path)
Then the embed call succeeds.
I tested this with cmd and bash, and both exhibited this behavior.
The text was updated successfully, but these errors were encountered:
The io/fs.FS package uses forward slashes for filenames, even on Windows. See https://golang.org/pkg/io/fs/#ValidPath:
"Note that paths are slash-separated on all systems, even Windows."
You should use path.Join, not filepath.Join for embed filenames.
Sorry, something went wrong.
It seems really unfortunate that embed doesn't accept filepaths used by the OS-- it almost feels like using path/filepath at all is a bad idea now.
path/filepath
But if that's what's decided, that's what's decided.
Successfully merging a pull request may close this issue.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, it is introduced by the latest release, which introduced
embed
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
With a file at
./assets/test.json
:What did you expect to see?
What did you see instead?
We can infer this is a path problem because if we instead do:
Then the embed call succeeds.
I tested this with cmd and bash, and both exhibited this behavior.
The text was updated successfully, but these errors were encountered: