-
-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced 'format' to encapsulate encoding and decoding formats toge…
…ther
- Loading branch information
Showing
11 changed files
with
253 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,10 @@ | ||
package yqlib | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"strings" | ||
) | ||
|
||
type InputFormat uint | ||
|
||
const ( | ||
YamlInputFormat = 1 << iota | ||
XMLInputFormat | ||
PropertiesInputFormat | ||
Base64InputFormat | ||
JsonInputFormat | ||
CSVObjectInputFormat | ||
TSVObjectInputFormat | ||
TomlInputFormat | ||
UriInputFormat | ||
LuaInputFormat | ||
) | ||
|
||
type Decoder interface { | ||
Init(reader io.Reader) error | ||
Decode() (*CandidateNode, error) | ||
} | ||
|
||
func InputFormatFromString(format string) (InputFormat, error) { | ||
switch format { | ||
case "yaml", "yml", "y": | ||
return YamlInputFormat, nil | ||
case "xml", "x": | ||
return XMLInputFormat, nil | ||
case "properties", "props", "p": | ||
return PropertiesInputFormat, nil | ||
case "json", "ndjson", "j": | ||
return JsonInputFormat, nil | ||
case "csv", "c": | ||
return CSVObjectInputFormat, nil | ||
case "tsv", "t": | ||
return TSVObjectInputFormat, nil | ||
case "toml": | ||
return TomlInputFormat, nil | ||
case "lua", "l": | ||
return LuaInputFormat, nil | ||
default: | ||
return 0, fmt.Errorf("unknown format '%v' please use [yaml|json|props|csv|tsv|xml|toml]", format) | ||
} | ||
} | ||
|
||
func FormatFromFilename(filename string) string { | ||
|
||
if filename != "" { | ||
GetLogger().Debugf("checking file extension '%s' for auto format detection", filename) | ||
nPos := strings.LastIndex(filename, ".") | ||
if nPos > -1 { | ||
format := filename[nPos+1:] | ||
GetLogger().Debugf("detected format '%s'", format) | ||
return format | ||
} | ||
} | ||
|
||
GetLogger().Debugf("using default inputFormat 'yaml'") | ||
return "yaml" | ||
} |
Oops, something went wrong.