// Package registry provides functionality for managing and accessing embedded file systems and directories. package registry import ( "embed" "io" "io/fs" "os" ) type Source interface { Open(name string) (fs.File, error) ReadFile(name string) ([]byte, error) ReadDir(name string) ([]fs.DirEntry, error) } type src struct{ fsys fs.FS } func (s src) Open(p string) (fs.File, error) { return s.fsys.Open(p) } func (s src) ReadFile(p string) ([]byte, error) { return fs.ReadFile(s.fsys, p) } func (s src) ReadDir(p string) ([]fs.DirEntry, error) { return fs.ReadDir(s.fsys, p) } func FromDir(path string) Source { return src{fsys: os.DirFS(path)} } //go:embed templates/* var templates embed.FS //go:embed schema-org/* var schemas embed.FS //go:embed aliases/* var aliases embed.FS func GetTemplates() Source { return src{fsys: templates} } func GetTemplate(name string) (string, error) { templateFile, err := templates.Open("templates/" + name + ".marka") if err != nil { return "", err } defer templateFile.Close() templateBytes, err := io.ReadAll(templateFile) if err != nil { return "", err } return string(templateBytes), nil } func GetSchemas() Source { return src{fsys: schemas} } func GetAliases() Source { return src{fsys: aliases} }