diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2020-02-27 22:40:37 -0500 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2020-02-27 22:54:44 -0500 |
| commit | 5e43a063c7ead13300c4639d31a2217b2dae3c4a (patch) | |
| tree | c673d317ad8e9095e5525bcfa2c8457cbd6f4fb7 /gomplate.go | |
| parent | f2ed18ff51656695035828cc72a0444144facd52 (diff) | |
Adding context.Context support and a logger
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'gomplate.go')
| -rw-r--r-- | gomplate.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/gomplate.go b/gomplate.go index 91e6bc91..d796c4dd 100644 --- a/gomplate.go +++ b/gomplate.go @@ -4,6 +4,7 @@ package gomplate import ( "bytes" + "context" "io" "os" "path" @@ -28,7 +29,7 @@ type gomplate struct { } // runTemplate - -func (g *gomplate) runTemplate(t *tplate) error { +func (g *gomplate) runTemplate(_ context.Context, t *tplate) error { tmpl, err := t.toGoTemplate(g) if err != nil { return err @@ -108,6 +109,11 @@ func parseTemplateArg(templateArg string, ta templateAliases) error { // RunTemplates - run all gomplate templates specified by the given configuration func RunTemplates(o *Config) error { + return RunTemplatesWithContext(context.Background(), o) +} + +// RunTemplatesWithContext - run all gomplate templates specified by the given configuration +func RunTemplatesWithContext(ctx context.Context, o *Config) error { Metrics = newMetrics() defer runCleanupHooks() // make sure config is sane @@ -127,16 +133,16 @@ func RunTemplates(o *Config) error { return err } funcMap := Funcs(d) - err = bindPlugins(o.Plugins, funcMap) + err = bindPlugins(ctx, o.Plugins, funcMap) if err != nil { return err } g := newGomplate(funcMap, o.LDelim, o.RDelim, nested, c) - return g.runTemplates(o) + return g.runTemplates(ctx, o) } -func (g *gomplate) runTemplates(o *Config) error { +func (g *gomplate) runTemplates(ctx context.Context, o *Config) error { start := time.Now() tmpl, err := gatherTemplates(o, chooseNamer(o, g)) Metrics.GatherDuration = time.Since(start) @@ -149,7 +155,7 @@ func (g *gomplate) runTemplates(o *Config) error { defer func() { Metrics.TotalRenderDuration = time.Since(start) }() for _, t := range tmpl { tstart := time.Now() - err := g.runTemplate(t) + err := g.runTemplate(ctx, t) Metrics.RenderDuration[t.name] = time.Since(tstart) if err != nil { Metrics.Errors++ |
