mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-05 16:15:56 +00:00
36 lines
650 B
Go
36 lines
650 B
Go
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://")
|
|
}
|