Support tcp scheme (#243)
Signed-off-by: Roman Vynar <roman.vynar@quiq.com>
Roman Vynar authored 1 year, 11 months ago
GitHub committed 1 year, 11 months ago
263 | 263 | case "http", "https", "file": |
264 | 264 | fetchStat = fetchHTTP(uri, sslVerify, proxyFromEnv, timeout) |
265 | 265 | case "unix": |
266 | fetchInfo = fetchUnix(u, showInfoCmd, timeout) | |
267 | fetchStat = fetchUnix(u, showStatCmd, timeout) | |
266 | fetchInfo = fetchUnix("unix", u.Path, showInfoCmd, timeout) | |
267 | fetchStat = fetchUnix("unix", u.Path, showStatCmd, timeout) | |
268 | case "tcp": | |
269 | fetchInfo = fetchUnix("tcp", u.Host, showInfoCmd, timeout) | |
270 | fetchStat = fetchUnix("tcp", u.Host, showStatCmd, timeout) | |
268 | 271 | default: |
269 | 272 | return nil, fmt.Errorf("unsupported scheme: %q", u.Scheme) |
270 | 273 | } |
353 | 356 | } |
354 | 357 | } |
355 | 358 | |
356 | func fetchUnix(u *url.URL, cmd string, timeout time.Duration) func() (io.ReadCloser, error) { | |
359 | func fetchUnix(scheme, address, cmd string, timeout time.Duration) func() (io.ReadCloser, error) { | |
357 | 360 | return func() (io.ReadCloser, error) { |
358 | f, err := net.DialTimeout("unix", u.Path, timeout) | |
361 | f, err := net.DialTimeout(scheme, address, timeout) | |
359 | 362 | if err != nil { |
360 | 363 | return nil, err |
361 | 364 | } |