Skip to content

Commit

Permalink
refactor: refactor and improve documentation for dynamic.go methods
Browse files Browse the repository at this point in the history
- Remove `exportloopref` linter from `.golangci.yml`
- Improve documentation for `AddFromFSFuncs` method in `dynamic.go`
- Refactor `templateBuilder` initialization for better readability in `dynamic.go`

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy committed Dec 28, 2024
1 parent d9566cc commit 92dd858
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ linters:
- dogsled
- dupl
- errcheck
- exportloopref
- exhaustive
- gochecknoinits
- goconst
Expand Down
26 changes: 23 additions & 3 deletions dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,30 @@ func (r DynamicRender) AddFromFS(name string, fsys fs.FS, files ...string) *temp
return builder.buildTemplate()
}

// AddFromFSFuncs supply add template from fs.FS (e.g. embed.FS) with callback func
func (r DynamicRender) AddFromFSFuncs(name string, funcMap template.FuncMap, fsys fs.FS, files ...string) *template.Template {
// AddFromFSFuncs adds a new template to the DynamicRender from the provided file system (fs.FS) and files.
// It allows you to specify a custom function map (funcMap) to be used within the template.
//
// Parameters:
// - name: The name to associate with the template in the DynamicRender.
// - funcMap: A map of functions to be used within the template.
// - fsys: The file system (fs.FS) from which to read the template files.
// - files: A variadic list of file paths to be included in the template.
//
// Returns:
// - *template.Template: The constructed template.
func (r DynamicRender) AddFromFSFuncs(
name string,
funcMap template.FuncMap,
fsys fs.FS,
files ...string,
) *template.Template {
tname := filepath.Base(files[0])
builder := &templateBuilder{templateName: tname, funcMap: funcMap, fsys: fsys, files: files}
builder := &templateBuilder{
templateName: tname,
funcMap: funcMap,
fsys: fsys,
files: files,
}
builder.buildType = fsFuncTemplateType
r[name] = builder
return builder.buildTemplate()
Expand Down

0 comments on commit 92dd858

Please sign in to comment.