forked from tleyden/elastic-thought
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blobstore.go
59 lines (47 loc) · 1.36 KB
/
blobstore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package elasticthought
import (
"fmt"
"io"
"log"
"net/url"
"time"
"github.com/couchbaselabs/cbfs/client"
)
// BlobStore provides a blob store interface.
type BlobStore interface {
Get(path string) (io.ReadCloser, error)
Put(srcname, dest string, r io.Reader, opts BlobPutOptions) error
Rm(fn string) error
OpenFile(path string) (BlobHandle, error)
}
// Calling OpenFile with a path on a BlobStore returns a
// BlobHandle which allows for reading and metadata.
type BlobHandle interface {
// The nodes that contain the file corresponding to this blob
// and the last time it was "scrubbed" (cbfs terminology)
Nodes() map[string]time.Time
}
type BlobPutOptions struct {
cbfsclient.PutOptions
}
func NewBlobStore(rawurl string) (BlobStore, error) {
// Three types of blob stores are supported:
// http://ip:port (cbfs)
// mock://mock (mock)
// file:///path/to/dir (local filesystem)
url, err := url.Parse(rawurl)
log.Printf("url: %v, scheme: %v, path: %v, err: %v", url, url.Scheme, url.Path, err)
switch url.Scheme {
case "http":
return NewCbfsBlobStore(rawurl)
case "mock":
return NewMockBlobStore(), nil
case "file":
return NewFileSystemBlobStore(url.Path)
default:
msg := "Unrecognized blob store URI: %v. If you are trying " +
"to use cbfs, make sure it ends with port 8484. " +
"or fix this code"
return nil, fmt.Errorf(msg)
}
}