MCPcopy Create free account
hub / github.com/appleboy/CodeGPT / loadTemplatesFromFS

Function loadTemplatesFromFS

util/template.go:82–106  ·  view source on GitHub ↗

loadTemplatesFromFS is a helper function that loads templates from the given filesystem and directory. It returns an error if reading the directory or parsing any template fails.

(fsys fs.FS, dir string)

Source from the content-addressed store, hash-verified

80// loadTemplatesFromFS is a helper function that loads templates from the given filesystem and directory.
81// It returns an error if reading the directory or parsing any template fails.
82func loadTemplatesFromFS(fsys fs.FS, dir string) error {
83 tmplFiles, err := fs.ReadDir(fsys, dir)
84 if err != nil {
85 return err
86 }
87
88 pattern := dir + "/"
89 if dir == "." {
90 pattern = ""
91 }
92
93 for _, tmpl := range tmplFiles {
94 if tmpl.IsDir() {
95 continue
96 }
97
98 pt, err := template.ParseFS(fsys, pattern+tmpl.Name())
99 if err != nil {
100 return err
101 }
102
103 templates[tmpl.Name()] = pt
104 }
105 return nil
106}

Callers 2

LoadTemplatesFunction · 0.85
LoadTemplatesFromDirFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected