-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathstorage.go
More file actions
29 lines (26 loc) · 774 Bytes
/
storage.go
File metadata and controls
29 lines (26 loc) · 774 Bytes
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
package gilfoyle
import (
"context"
"fmt"
"github.com/dreamvo/gilfoyle/config"
"github.com/dreamvo/gilfoyle/storage"
"github.com/dreamvo/gilfoyle/storage/fs"
"github.com/dreamvo/gilfoyle/storage/gcs"
"github.com/dreamvo/gilfoyle/storage/s3"
)
// NewStorage creates a new storage instance
func NewStorage(driver config.StorageDriver) (storage.Storage, error) {
cfg := Config.Storage
switch driver {
case storage.Filesystem:
return fs.NewStorage(fs.Config{
Root: cfg.Filesystem.DataPath,
}), nil
case storage.GoogleCloudStorage:
return gcs.NewStorage(context.Background(), cfg.GCS.CredentialsFile, cfg.GCS.Bucket)
case storage.AmazonS3:
return s3.NewStorage(cfg.S3)
default:
return nil, fmt.Errorf("storage driver %s does not exist", driver)
}
}