Skip to content

Commit

Permalink
Merge pull request #45 from crazy-max/backport
Browse files Browse the repository at this point in the history
Backport from paerser
  • Loading branch information
crazy-max committed May 5, 2023
2 parents 8186b30 + 26c45eb commit 05b3131
Show file tree
Hide file tree
Showing 22 changed files with 1,139 additions and 159 deletions.
8 changes: 4 additions & 4 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func Decode(environ []string, prefix string, element interface{}) error {

vars := make(map[string]string)
for _, evr := range environ {
n := strings.SplitN(evr, "=", 2)
if strings.HasPrefix(strings.ToUpper(n[0]), prefix) {
key := strings.ReplaceAll(strings.ToLower(n[0]), "_", ".")
vars[key] = n[1]
k, v, _ := strings.Cut(evr, "=")
if strings.HasPrefix(strings.ToUpper(k), prefix) {
key := strings.ReplaceAll(strings.ToLower(k), "_", ".")
vars[key] = v
}
}

Expand Down
4 changes: 2 additions & 2 deletions env/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func getRootPrefixes(element interface{}, prefix string) []string {
func getPrefixes(prefix string, rootType reflect.Type) []string {
var names []string

if rootType.Kind() == reflect.Ptr {
if rootType.Kind() == reflect.Pointer {
rootType = rootType.Elem()
}

Expand All @@ -52,7 +52,7 @@ func getPrefixes(prefix string, rootType reflect.Type) []string {
}

if field.Anonymous &&
(field.Type.Kind() == reflect.Ptr && field.Type.Elem().Kind() == reflect.Struct || field.Type.Kind() == reflect.Struct) {
(field.Type.Kind() == reflect.Pointer && field.Type.Elem().Kind() == reflect.Struct || field.Type.Kind() == reflect.Struct) {
names = append(names, getPrefixes(prefix, field.Type)...)
continue
}
Expand Down
6 changes: 3 additions & 3 deletions file/file_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func decodeFileToNode(filePath string, filters ...string) (*parser.Node, error)
return nil, err
}

case ".yml", ".yaml":
case ".yml", ".yaml", ".json":
err = yaml.Unmarshal(content, data)
if err != nil {
return nil, err
Expand Down Expand Up @@ -68,7 +68,7 @@ func getRootFieldNames(element interface{}) []string {
func getFieldNames(rootType reflect.Type) []string {
var names []string

if rootType.Kind() == reflect.Ptr {
if rootType.Kind() == reflect.Pointer {
rootType = rootType.Elem()
}

Expand All @@ -84,7 +84,7 @@ func getFieldNames(rootType reflect.Type) []string {
}

if field.Anonymous &&
(field.Type.Kind() == reflect.Ptr && field.Type.Elem().Kind() == reflect.Struct || field.Type.Kind() == reflect.Struct) {
(field.Type.Kind() == reflect.Pointer && field.Type.Elem().Kind() == reflect.Struct || field.Type.Kind() == reflect.Struct) {
names = append(names, getFieldNames(field.Type)...)
continue
}
Expand Down

0 comments on commit 05b3131

Please sign in to comment.