I want to embed a file placed one level above the golang file code. for example:
dir1
dir2
How to embed file.txt inside file.go using go:embed?
The documentation states:
Patterns may not contain ‘.’ or ‘..’ or empty path elements, nor may they begin or end with a slash.
So what you are trying to do is not supported directly. Further information is available in the comments on this issue.
One thing you can do is to put a go file in dir2
, embed file.txt
in that and then import/use that in dir1/file.go
(assuming the folders are in the same package).