-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
Description
What version of Go are you using (go version
)?
$ go version go version go1.16 windows/amd64
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
Output
$ go env set GOARCH=amd64 set GOHOSTARCH=amd64 set GOHOSTOS=windows
What did you do?
With a file at ./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))
}
What did you expect to see?
$ go run main.go
{"hello":"world"}
{"hello":"world"}
What did you see instead?
$ 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.