readFromPath creates a ReadCloser from the given path. The path must be either a valid file or an HTTP/HTTPS endpoint. Returns an error if there is any failure in building ReadCloser.
(ctx context.Context, path string, insecureSkipVerify bool)
| 623 | // readFromPath creates a ReadCloser from the given path. The path must be either a valid file |
| 624 | // or an HTTP/HTTPS endpoint. Returns an error if there is any failure in building ReadCloser. |
| 625 | func readFromPath(ctx context.Context, path string, insecureSkipVerify bool) (rc io.ReadCloser, err error) { |
| 626 | messageFormat := "Loading content from [%s] ..." |
| 627 | if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") { |
| 628 | base.InfofCtx(ctx, base.KeyAll, messageFormat, path) |
| 629 | client := base.GetHttpClient(insecureSkipVerify) |
| 630 | resp, err := client.Get(path) |
| 631 | if err != nil { |
| 632 | return nil, err |
| 633 | } else if resp.StatusCode >= 300 { |
| 634 | _ = resp.Body.Close() |
| 635 | return nil, base.NewHTTPError(resp.StatusCode, http.StatusText(resp.StatusCode)) |
| 636 | } |
| 637 | rc = resp.Body |
| 638 | } else if base.FileExists(path) { |
| 639 | base.InfofCtx(ctx, base.KeyAll, messageFormat, path) |
| 640 | rc, err = os.Open(path) |
| 641 | if err != nil { |
| 642 | return nil, err |
| 643 | } |
| 644 | } else { |
| 645 | return nil, ErrPathNotFound |
| 646 | } |
| 647 | return rc, nil |
| 648 | } |
| 649 | |
| 650 | // GetBucketName returns the bucket name associated with the database config. |
| 651 | func (dbConfig *DbConfig) GetBucketName() string { |
no test coverage detected