afero icon indicating copy to clipboard operation
afero copied to clipboard

Unable to use with text/template

Open fugkco opened this issue 3 years ago • 1 comments

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)

fugkco avatar Sep 18 '21 17:09 fugkco

You have to convert afero.Fs to an afero.IOFS

	fs := afero.NewOsFs()
	template.New("somedir").ParseFS(afero.NewIOFS(fs))

AndrusGerman avatar May 02 '22 16:05 AndrusGerman