Documentation

Overview

Example (OpenBucketFromURL)
Output:

hello world

Index

Examples

Constants

View Source
const Scheme = "file"

    Scheme is the URL scheme fileblob registers its URLOpener under on blob.DefaultMux.

    Variables

    This section is empty.

    Functions

    func OpenBucket

    func OpenBucket(dir string, opts *Options) (*blob.Bucket, error)

      OpenBucket creates a *blob.Bucket backed by the filesystem and rooted at dir, which must exist. See the package documentation for an example.

      Example
      Output:
      
      

      Types

      type Options

      type Options struct {
      	// URLSigner implements signing URLs (to allow access to a resource without
      	// further authorization) and verifying that a given URL is unexpired and
      	// contains a signature produced by the URLSigner.
      	// URLSigner is only required for utilizing the SignedURL API.
      	URLSigner URLSigner
      
      	// If true, create the directory backing the Bucket if it does not exist
      	// (using os.MkdirAll).
      	CreateDir bool
      }

        Options sets options for constructing a *blob.Bucket backed by fileblob.

        type URLOpener

        type URLOpener struct {
        	// Options specifies the default options to pass to OpenBucket.
        	Options Options
        }

          URLOpener opens file bucket URLs like "file:///foo/bar/baz".

          The URL's host is ignored unless it is ".", which is used to signal a relative path. For example, "file://./../.." uses "../.." as the path.

          If os.PathSeparator != "/", any leading "/" from the path is dropped and remaining '/' characters are converted to os.PathSeparator.

          The following query parameters are supported:

          - create_dir: (any non-empty value) the directory is created (using os.MkDirAll)
            if it does not already exist.
          - base_url: the base URL to use to construct signed URLs; see URLSignerHMAC
          - secret_key_path: path to read for the secret key used to construct signed URLs;
            see URLSignerHMAC
          

          If either of base_url / secret_key_path are provided, both must be.

          - file:///a/directory
            -> Passes "/a/directory" to OpenBucket.
          - file://localhost/a/directory
            -> Also passes "/a/directory".
          - file://./../..
            -> The hostname is ".", signaling a relative path; passes "../..".
          - file:///c:/foo/bar on Windows.
            -> Passes "c:\foo\bar".
          - file://localhost/c:/foo/bar on Windows.
            -> Also passes "c:\foo\bar".
          - file:///a/directory?base_url=/show&secret_key_path=secret.key
            -> Passes "/a/directory" to OpenBucket, and sets Options.URLSigner
               to a URLSignerHMAC initialized with base URL "/show" and secret key
               bytes read from the file "secret.key".
          

          func (*URLOpener) OpenBucketURL

          func (o *URLOpener) OpenBucketURL(ctx context.Context, u *url.URL) (*blob.Bucket, error)

            OpenBucketURL opens a blob.Bucket based on u.

            type URLSigner

            type URLSigner interface {
            	// URLFromKey defines how the bucket's object key will be turned
            	// into a signed URL. URLFromKey must be safe to call from multiple goroutines.
            	URLFromKey(ctx context.Context, key string, opts *driver.SignedURLOptions) (*url.URL, error)
            
            	// KeyFromURL must be able to validate a URL returned from URLFromKey.
            	// KeyFromURL must only return the object if if the URL is
            	// both unexpired and authentic. KeyFromURL must be safe to call from
            	// multiple goroutines. Implementations of KeyFromURL should not modify
            	// the URL argument.
            	KeyFromURL(ctx context.Context, surl *url.URL) (string, error)
            }

              URLSigner defines an interface for creating and verifying a signed URL for objects in a fileblob bucket. Signed URLs are typically used for granting access to an otherwise-protected resource without requiring further authentication, and callers should take care to restrict the creation of signed URLs as is appropriate for their application.

              type URLSignerHMAC

              type URLSignerHMAC struct {
              	// contains filtered or unexported fields
              }

                URLSignerHMAC signs URLs by adding the object key, expiration time, and a hash-based message authentication code (HMAC) into the query parameters. Values of URLSignerHMAC with the same secret key will accept URLs produced by others as valid.

                func NewURLSignerHMAC

                func NewURLSignerHMAC(baseURL *url.URL, secretKey []byte) *URLSignerHMAC

                  NewURLSignerHMAC creates a URLSignerHMAC. If the secret key is empty, then NewURLSignerHMAC panics.

                  func (*URLSignerHMAC) KeyFromURL

                  func (h *URLSignerHMAC) KeyFromURL(ctx context.Context, sURL *url.URL) (string, error)

                    KeyFromURL checks expiry and signature, and returns the object key only if the signed URL is both authentic and unexpired.

                    func (*URLSignerHMAC) URLFromKey

                    func (h *URLSignerHMAC) URLFromKey(ctx context.Context, key string, opts *driver.SignedURLOptions) (*url.URL, error)

                      URLFromKey creates a signed URL by copying the baseURL and appending the object key, expiry, and signature as a query params.