From 9a70861e4bc8fa43b374c55ad603d12429032d2c Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 17 May 2023 15:00:27 +0200 Subject: [PATCH] address some comments --- cmd/init/init.go | 4 ++-- libs/template/execute.go | 4 ++-- libs/template/schema.go | 13 ++++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cmd/init/init.go b/cmd/init/init.go index 8ffb129a3..07d9ec7b9 100644 --- a/cmd/init/init.go +++ b/cmd/init/init.go @@ -12,7 +12,7 @@ import ( const ConfigFileName = "config.json" const SchemaFileName = "schema.json" -const TemplateDirname = "template" +const TemplateDirName = "template" var initCmd = &cobra.Command{ Use: "init", @@ -58,7 +58,7 @@ var initCmd = &cobra.Command{ } // materialize the template - return template.WalkFileTree(config, filepath.Join(args[0], TemplateDirname), targetDir) + return template.WalkFileTree(config, filepath.Join(args[0], TemplateDirName), targetDir) }, } diff --git a/libs/template/execute.go b/libs/template/execute.go index d5fb88fb3..09cf8c59b 100644 --- a/libs/template/execute.go +++ b/libs/template/execute.go @@ -7,11 +7,11 @@ import ( "text/template" ) -// Executes the template by appling config on it. Returns the materialized config +// Executes the template by applying config on it. Returns the materialized config // as a string func executeTemplate(config map[string]any, templateDefination string) (string, error) { // configure template with helper functions - tmpl, err := template.New("foo").Funcs(HelperFuncs).Parse(templateDefination) + tmpl, err := template.New("").Funcs(HelperFuncs).Parse(templateDefination) if err != nil { return "", err } diff --git a/libs/template/schema.go b/libs/template/schema.go index e8187fa54..2023eaf90 100644 --- a/libs/template/schema.go +++ b/libs/template/schema.go @@ -92,13 +92,6 @@ func validateType(v any, fieldType FieldType) error { // TODO: add validation check for regex for string types func (schema Schema) ValidateConfig(config map[string]any) error { - // assert all fields are defined in - for k := range schema { - if _, ok := config[k]; !ok { - return fmt.Errorf("input parameter %s is not defined in config", k) - } - } - // validate types defined in config for k, v := range config { fieldMetadata, ok := schema[k] @@ -110,5 +103,11 @@ func (schema Schema) ValidateConfig(config map[string]any) error { return fmt.Errorf("incorrect type for %s. %w", k, err) } } + // assert all fields are defined in + for k := range schema { + if _, ok := config[k]; !ok { + return fmt.Errorf("input parameter %s is not defined in config", k) + } + } return nil }