Helper func: Read input from specified file or stdin
(p string)
| 76 | |
| 77 | // Helper func: Read input from specified file or stdin |
| 78 | func loadData(p string) (_ []byte, retErr error) { |
| 79 | if p == "" { |
| 80 | return nil, fmt.Errorf("no path specified") |
| 81 | } |
| 82 | |
| 83 | var rdr io.Reader |
| 84 | switch p { |
| 85 | case "-": |
| 86 | rdr = os.Stdin |
| 87 | case "+": |
| 88 | return []byte("{}"), nil |
| 89 | default: |
| 90 | f, err := os.Open(p) |
| 91 | if err != nil { |
| 92 | return nil, err |
| 93 | } |
| 94 | rdr = f |
| 95 | defer func() { |
| 96 | retErr = errors.Join(retErr, f.Close()) |
| 97 | }() |
| 98 | } |
| 99 | return io.ReadAll(rdr) |
| 100 | } |
| 101 | |
| 102 | // Print a json object in accordance with the prophecy (or the command line options) |
| 103 | func printJSON(j any) error { |
no outgoing calls
no test coverage detected