ParseFormat parses a format string into a Format value. The second return value is false if the format string was not recognized, in which case FormatJSON is returned as default.
(s string)
| 19 | // The second return value is false if the format string was not recognized, |
| 20 | // in which case FormatJSON is returned as default. |
| 21 | func ParseFormat(s string) (Format, bool) { |
| 22 | switch strings.ToLower(s) { |
| 23 | case "json", "": |
| 24 | return FormatJSON, true |
| 25 | case "ndjson": |
| 26 | return FormatNDJSON, true |
| 27 | case "table": |
| 28 | return FormatTable, true |
| 29 | case "csv": |
| 30 | return FormatCSV, true |
| 31 | default: |
| 32 | return FormatJSON, false |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | // String returns the string representation of a Format. |
| 37 | func (f Format) String() string { |
no outgoing calls