From cec23e66f9bd5022845162ae4dd3f2633b5236fa Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sat, 28 May 2022 19:24:48 -0400 Subject: General refactoring & cleanup Signed-off-by: Dave Henderson --- gomplate.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'gomplate.go') diff --git a/gomplate.go b/gomplate.go index a036b392..91d1e026 100644 --- a/gomplate.go +++ b/gomplate.go @@ -26,7 +26,6 @@ type gomplate struct { tmplctx interface{} funcMap template.FuncMap nestedTemplates templateAliases - rootTemplate *template.Template leftDelim, rightDelim string } @@ -128,6 +127,14 @@ func Run(ctx context.Context, cfg *config.Config) error { Metrics = newMetrics() defer runCleanupHooks() + // reset defaults before validation + cfg.ApplyDefaults() + + err := cfg.Validate() + if err != nil { + return fmt.Errorf("failed to validate config: %w\n%+v", err, cfg) + } + d := data.FromConfig(ctx, cfg) log.Debug().Str("data", fmt.Sprintf("%+v", d)).Msg("created data from config") @@ -136,10 +143,16 @@ func Run(ctx context.Context, cfg *config.Config) error { if err != nil { return err } - c, err := createTmplContext(ctx, cfg.Context, d) + + aliases := []string{} + for k := range cfg.Context { + aliases = append(aliases, k) + } + c, err := createTmplContext(ctx, aliases, d) if err != nil { return err } + funcMap := CreateFuncs(ctx, d) err = bindPlugins(ctx, cfg, funcMap) if err != nil { -- cgit v1.2.3