readFile load a file from stdin, the local directory, or a remote file with a url.
(filePath string, p getter.Providers)
| 117 | |
| 118 | // readFile load a file from stdin, the local directory, or a remote file with a url. |
| 119 | func readFile(filePath string, p getter.Providers) ([]byte, error) { |
| 120 | if strings.TrimSpace(filePath) == "-" { |
| 121 | return io.ReadAll(os.Stdin) |
| 122 | } |
| 123 | u, err := url.Parse(filePath) |
| 124 | if err != nil { |
| 125 | return nil, err |
| 126 | } |
| 127 | |
| 128 | // FIXME: maybe someone handle other protocols like ftp. |
| 129 | g, err := p.ByScheme(u.Scheme) |
| 130 | if err != nil { |
| 131 | return os.ReadFile(filePath) |
| 132 | } |
| 133 | data, err := g.Get(filePath, getter.WithURL(filePath)) |
| 134 | if err != nil { |
| 135 | return nil, err |
| 136 | } |
| 137 | return data.Bytes(), nil |
| 138 | } |
searching dependent graphs…