Help us shape the future of Go! Take the 2026 Go Developer Survey

storage

package module
v0.0.0-...-89dab59 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2019 License: MIT Imports: 8 Imported by: 0

README

storage

storage in go

Usage

Install
go get -u github.com/xpzouying/storage
Example

import "github.com/xpzouying/storage"

l, _ := storage.NewLocal("/tmp/oss")

buf := bytes.NewBuffer("hello storage")
l.Put(context.Background(), "file1", buf)


rc, _, := l.Get(context.Background(), "file1")
data, _ := ioutil.ReadAll(rc)
rc.Close()

log.Printf("read data: %s\n", data)
Test
go test -v github.com/xpzouying/storage

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyURI = errors.New("empty uri")
)

Functions

This section is empty.

Types

type Local

type Local string

Local is local storage in local filesystem

func NewLocal

func NewLocal(path string) (*Local, error)

func (Local) Close

func (l Local) Close() error

Close storage

func (Local) Delete

func (l Local) Delete(ctx context.Context, uri string) error

Delete object by uri

func (Local) Get

func (l Local) Get(ctx context.Context, uri string) (rc io.ReadCloser, err error)

Get object by uri

func (Local) Put

func (l Local) Put(ctx context.Context, uri string, r io.Reader) error

Put data and return uri for object uri could be multi-level directory, split by '/'

type Storage

type Storage interface {

	// Put data and return uri for object
	Put(ctx context.Context, uri string, r io.Reader) error

	// Get object by uri
	Get(ctx context.Context, uri string) (rc io.ReadCloser, err error)

	// Delete object by uri
	Delete(ctx context.Context, uri string) error

	// Close storage
	Close() error
}

Storage for object

Jump to

Keyboard shortcuts

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