Skip to content

Commit

Permalink
lib/memfs: call the Init method in the embedded file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shuLhan committed Oct 29, 2023
1 parent 72e51cb commit d714934
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/memfs/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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}}",
Expand All @@ -120,6 +120,11 @@ func init() {
{{- end}}
{{$varname}}.Root = {{$varname}}.PathNodes.Get("/")
var err = {{$varname}}.Init()
if err != nil {
panic("{{$varname}}: " + err.Error())
}
}
{{end}}
`
Expand Down

0 comments on commit d714934

Please sign in to comment.