refactor: minor changes and fixes
This commit is contained in:
parent
47c9d48735
commit
505dbefb67
2 changed files with 19 additions and 5 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
|
@ -92,11 +93,11 @@ func Unmarshal(data []byte, v any, inFormat DataFormat) error {
|
|||
// both the standard default format (JSON) and any command line
|
||||
// change to that provided by options.
|
||||
func DataFormatFromFileExt(path string, defaultFmt DataFormat) DataFormat {
|
||||
switch filepath.Ext(path) {
|
||||
case ".json", ".JSON":
|
||||
switch strings.TrimLeft(strings.ToLower(filepath.Ext(path)), ".") {
|
||||
case JSON.String():
|
||||
// The file is a JSON file
|
||||
return JSON
|
||||
case ".yaml", ".yml", ".YAML", ".YML":
|
||||
case YAML.String(), "yml":
|
||||
// The file is a YAML file
|
||||
return YAML
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue