memblob

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2019 License: Apache-2.0 Imports: 14 Imported by: 75

Documentation

Overview

Package memblob provides an in-memory blob implementation. Use OpenBucket to construct a *blob.Bucket.

Open URLs

For blob.OpenBucket URLs, memblob registers for the scheme "mem"; URLs are always "mem://". For more details, see URLOpener.

As

memblob does not support any types for As.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"gocloud.dev/blob/memblob"
)

func main() {

	// Create an in-memory bucket.
	b := memblob.OpenBucket(nil)

	// Now we can use b to read or write files to the container.
	ctx := context.Background()
	err := b.WriteAll(ctx, "my-key", []byte("hello world"), nil)
	if err != nil {
		log.Fatal(err)
	}
	data, err := b.ReadAll(ctx, "my-key")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(data))

}
Output:

hello world
Example (Open)
package main

import (
	"context"
	"fmt"
	"log"

	"gocloud.dev/blob"
)

func main() {
	// Open creates a *blob.Bucket from a URL.
	b, err := blob.OpenBucket(context.Background(), "mem://")
	if err != nil {
		log.Fatal(err)
	}

	// Now we can use b to read or write files to the container.
	ctx := context.Background()
	err = b.WriteAll(ctx, "my-key", []byte("hello world"), nil)
	if err != nil {
		log.Fatal(err)
	}
	data, err := b.ReadAll(ctx, "my-key")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(data))

}
Output:

hello world

Index

Examples

Constants

View Source
const Scheme = "mem"

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

Variables

This section is empty.

Functions

func OpenBucket

func OpenBucket(opts *Options) *blob.Bucket

OpenBucket creates a *blob.Bucket backed by memory.

Types

type Options

type Options struct{}

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

type URLOpener added in v0.10.0

type URLOpener struct{}

URLOpener opens URLs like "mem://".

func (*URLOpener) OpenBucketURL added in v0.10.0

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

OpenBucketURL returns a new in-memory bucket.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL