-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.go
71 lines (58 loc) · 2.28 KB
/
storage.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
60
61
62
63
64
65
66
67
68
69
70
71
// Package storage creates an interface for several key/value storage technologies.
package storage
import (
"github.com/kyani-inc/storage/providers/bolt"
"github.com/kyani-inc/storage/providers/dynamodb"
"github.com/kyani-inc/storage/providers/elasticsearch"
"github.com/kyani-inc/storage/providers/folder"
"github.com/kyani-inc/storage/providers/local"
"github.com/kyani-inc/storage/providers/memcached"
"github.com/kyani-inc/storage/providers/redis"
"github.com/kyani-inc/storage/providers/s3"
)
// Storage represents a storage facility agnostic of the backing technology.
type Storage interface {
// Get returns data by key. Missing keys return `nil`.
Get(key string) []byte
// Put will overwrite data by key.
Put(key string, data []byte) error
// Delete will attempt to remove a value by key. Idempotent.
Delete(key string)
// Flush clears all keys from the storage. Idempotent.
Flush()
}
// Bolt utilizes a BoltDB database (https://github.com/boltdb/bolt) for storage.
func Bolt(path string) (Storage, error) {
return bolt.New(path)
}
// Local uses the applications memory for storage.
func Local() Storage {
return local.New()
}
// Folder uses the application's underlying file structure for storage.
func Folder(path string) (Storage, error) {
return folder.New(path)
}
// S3 uses Amazon AWS S3 for storage.
//
// Every key combined with the prefix (to support Flush) and a possible extension determined by content.
// The field content is the content type to use with all keys. For example: "application/json; charset=utf-8".
func S3(access, secret, bucket, region, content, prefix string) (Storage, error) {
return s3.New(access, secret, bucket, region, content, prefix)
}
// Redis uses a Redis instance for storage.
func Redis(host, port string) Storage {
return redis.New(host, port)
}
// Memcache uses one or more Memcache hosts for storage.
func Memcached(hosts []string) Storage {
return memcached.New(hosts)
}
// AWS DynamoDB storage.
func DynamoDB(access string, secret string, region string, table string) (Storage, error) {
return dynamodb.New(access, secret, region, table)
}
// ElasticSearch storage
func ElasticSearch(host, scheme, index, namespace, awsKey, awsSecret string) (Storage, error) {
return elasticsearch.New(host, scheme, index, namespace, awsKey, awsSecret)
}