Skip to content

Read files and render templates from an embedded file system.

License

Notifications You must be signed in to change notification settings

spectrocloud-labs/embeddedfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributions Welcome License Test Go Report Card codecov Go Reference

embeddedfs

The embeddedfs package reads files and renders templates from an embedded file system.

Usage

Assuming you have the following directory structure:

.
├── main.go
└── myresources
    └── mytemplate.tmpl

And mytemplate.tmpl defined as follows:

Name: {{ .Name }}

Then the following code will produce out.yaml with the content Name: Bob:

//go:embed resources/*
var resources embed.FS

func main() {
    e := embeddedfs.NewEmbeddedFS("myresources", resources)
    args := map[string]interface{}{
        "Name": "Bob",
    }
    if err := e.RenderTemplate(args, "", "mytemplate.tmpl", "out.yaml"); err != nil {
        return fmt.Errorf("failed to render my template: %w", err)
    }
}

About

Read files and render templates from an embedded file system.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •