From d714934c3b42d9fba7c8751532f92cb61c23e1e2 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 29 Oct 2023 17:08:15 +0700 Subject: [PATCH] lib/memfs: call the Init method in the embedded file By calling the Init method, the regular expression for include and excludes is initialized, which allow using any method of MemFS instance later, for example the Watch method. While at it, fix the fields alignment in template code format. --- lib/memfs/template.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/memfs/template.go b/lib/memfs/template.go index c59eae56..747dddd7 100644 --- a/lib/memfs/template.go +++ b/lib/memfs/template.go @@ -89,7 +89,7 @@ func init() { {{$varname}} = &memfs.MemFS{ PathNodes: memfs.NewPathNode(), Opts: &memfs.Options{ - Root: "{{.Opts.Root}}", + Root: "{{.Opts.Root}}", MaxFileSize: {{.Opts.MaxFileSize}}, Includes: []string{ {{- range $v := .Opts.Includes}} @@ -102,7 +102,7 @@ func init() { {{- end}} }, Embed: memfs.EmbedOptions{ - CommentHeader: ` + "`" + `{{.Opts.Embed.CommentHeader}}` + "`" + `, + CommentHeader: ` + "`" + `{{.Opts.Embed.CommentHeader}}` + "`" + `, PackageName: "{{.Opts.Embed.PackageName}}", VarName: "{{.Opts.Embed.VarName}}", GoFileName: "{{.Opts.Embed.GoFileName}}", @@ -120,6 +120,11 @@ func init() { {{- end}} {{$varname}}.Root = {{$varname}}.PathNodes.Get("/") + + var err = {{$varname}}.Init() + if err != nil { + panic("{{$varname}}: " + err.Error()) + } } {{end}} `