mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 03:47:51 +00:00
s3 storage abstraction
This commit is contained in:
parent
ec298a096c
commit
15c53cff19
1 changed files with 36 additions and 0 deletions
36
util/storage.go
Normal file
36
util/storage.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"pilosa/config"
|
||||
"strings"
|
||||
|
||||
"github.com/kr/s3/s3util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
access_key := config.GetString("AWS_ACCESS_KEY_ID")
|
||||
secret := config.GetString("AWS_SECRET_ACCESS_KEY")
|
||||
|
||||
s3util.DefaultConfig.AccessKey = access_key
|
||||
s3util.DefaultConfig.SecretKey = secret
|
||||
}
|
||||
|
||||
func Open(s string) (io.ReadCloser, error) {
|
||||
if isURL(s) {
|
||||
return s3util.Open(s, nil)
|
||||
}
|
||||
return os.Open(s)
|
||||
}
|
||||
|
||||
func Create(s string) (io.WriteCloser, error) {
|
||||
if isURL(s) {
|
||||
return s3util.Create(s, nil, nil)
|
||||
}
|
||||
return os.Create(s)
|
||||
}
|
||||
|
||||
func isURL(s string) bool {
|
||||
return strings.HasPrefix(s, "http://") || strings.HasPrefix(s, "https://")
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue