From 92dd85825bc5e781249c11529543e20fa94e638c Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 28 Dec 2024 16:54:56 +0800 Subject: [PATCH] refactor: refactor and improve documentation for dynamic.go methods - 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 --- .golangci.yml | 1 - dynamic.go | 26 +++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d59c99b..67edf0a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,7 +7,6 @@ linters: - dogsled - dupl - errcheck - - exportloopref - exhaustive - gochecknoinits - goconst diff --git a/dynamic.go b/dynamic.go index f00816f..2e8577c 100644 --- a/dynamic.go +++ b/dynamic.go @@ -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()