afero
afero copied to clipboard
Unable to use with text/template
Trying to use template.ParseFS()
isn't possible because fs.FS
implements Open(fs.File, error)
where afero implements Open(afero.File, error)
./template.go:84:12: cannot use t.fs (type afero.Fs) as type fs.FS in argument to "text/template".New(filepath.Base(src)).Funcs(sprig.TxtFuncMap()).Funcs("text/template".FuncMap{...}).Delims(t.delims.left, t.delims.right).Option(option).ParseFS:
afero.Fs does not implement fs.FS (wrong type for Open method)
have Open(string) (afero.File, error)
want Open(string) (fs.File, error)
Sample code:
fs := afero.NewOsFs()
template.New("somedir").ParseFS(fs, src)
You have to convert afero.Fs to an afero.IOFS
fs := afero.NewOsFs()
template.New("somedir").ParseFS(afero.NewIOFS(fs))