Download retrieves content from the given url and write it to path.
(url, path string, rfs ...RequestFunc)
| 72 | |
| 73 | // Download retrieves content from the given url and write it to path. |
| 74 | func Download(url, path string, rfs ...RequestFunc) error { |
| 75 | // download may take more time |
| 76 | cl := New(UnsetTimeout()) |
| 77 | res, err := cl.Get(url, rfs...) |
| 78 | if err != nil { |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | f, err := os.Create(path) |
| 83 | if err != nil { |
| 84 | return err |
| 85 | } |
| 86 | defer func() { |
| 87 | _ = f.Close() |
| 88 | }() |
| 89 | |
| 90 | _, err = io.Copy(f, bytes.NewReader(res.Body())) |
| 91 | |
| 92 | return err |
| 93 | } |
| 94 | |
| 95 | // New TODO: need to config tls security |
| 96 | func New(cfs ...ClientFunc) *Client { |
nothing calls this directly
no test coverage detected