Updated README.md

This commit is contained in:
David Allen 2024-07-03 10:03:16 -06:00
parent 2b064c2700
commit 708980831b
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC

View file

@ -53,10 +53,12 @@ This will do the same thing as the `generate` subcommand, but remotely.
The `configurator` uses generator plugins to define how config files are generated using a `Generator` interface. The interface is defined like so: The `configurator` uses generator plugins to define how config files are generated using a `Generator` interface. The interface is defined like so:
```go ```go
type Files = map[string][]byte
type Generator interface { type Generator interface {
GetName() string GetName() string
GetGroups() []string GetVersion() string
Generate(config *configurator.Config, opts ...util.Option) ([]byte, error) GetDescription() string
Generate(config *configurator.Config, opts ...util.Option) (Files, error)
} }
``` ```
@ -68,7 +70,17 @@ package main
type MyGenerator struct {} type MyGenerator struct {}
func (g *MyGenerator) GetName() string { func (g *MyGenerator) GetName() string {
return "my-generator" // just an example...this can be done however you want
pluginInfo := LoadFromFile("path/to/plugin/info.json")
return pluginInfo["name"]
}
func (g *MyGenerator) GetVersion() string {
return "v1.0.0"
}
func (g *MyGenerator) GetDescription() string {
return "This is an example plugin."
} }
func (g *MyGenerator) Generate(config *configurator.Config, opts ...util.Option) (map[string][]byte, error) { func (g *MyGenerator) Generate(config *configurator.Config, opts ...util.Option) (map[string][]byte, error) {
@ -83,7 +95,7 @@ func (g *MyGenerator) Generate(config *configurator.Config, opts ...util.Option)
// ... blah, blah, blah, format output, and so on... // ... blah, blah, blah, format output, and so on...
} }
// apply the template and get substituted output as byte array // apply the substitutions to Jinja template and return output as byte array
return generator.ApplyTemplate(path, generator.Mappings{ return generator.ApplyTemplate(path, generator.Mappings{
"hosts": output, "hosts": output,
}) })