Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hspitzley-czi committed Mar 6, 2024
1 parent b57589a commit b3ceef8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 52 deletions.
19 changes: 17 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package config

import (
"bytes"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"text/template"

"github.com/go-playground/validator/v10"
"github.com/mitchellh/mapstructure"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -181,8 +183,7 @@ func evaluateConfigWithEnv(configFile io.Reader, writers ...io.Writer) (io.Reade
return nil, fmt.Errorf("unable to read the config file: %w", err)
}

// t := template.New("appConfigTemplate").Option("missingkey=zero")
t := template.New("appConfigTemplate")
t := template.New("appConfigTemplate").Option("missingkey=zero")
tmpl, err := t.Parse(string(b))
if err != nil {
return nil, fmt.Errorf("unable to parse template from: \n%s: %w", string(b), err)
Expand All @@ -205,3 +206,17 @@ func getAppEnv() string {
}
return env
}

func validateConfiguration[T any](cfg *T) error {
validate := validator.New()
err := validate.Struct(*cfg)
fmt.Println("...validateConfiguration, cfg:", cfg)
fmt.Println("...validateConfiguration, err:", err)
if err != nil {
errSlice := &validator.ValidationErrors{}
errors.As(err, errSlice)
return errSlice
}

return nil
}
1 change: 0 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ blah2=test2`
b, err := io.ReadAll(eval)
r.NoError(err)
r.Equal(expected, string(b))
r.Equal(true, false)
}

func TesEvaluateConfigWithMissingEnv(t *testing.T) {
Expand Down
49 changes: 0 additions & 49 deletions config/validation.go

This file was deleted.

0 comments on commit b3ceef8

Please sign in to comment.