MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / readFromPath

Function readFromPath

rest/config.go:625–648  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
625func 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.
651func (dbConfig *DbConfig) GetBucketName() string {

Callers 3

LoadLegacyServerConfigFunction · 0.85
loadJavaScriptFunction · 0.85

Calls 6

InfofCtxFunction · 0.92
GetHttpClientFunction · 0.92
NewHTTPErrorFunction · 0.92
FileExistsFunction · 0.92
CloseMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected