mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-14 06:48:02 +00:00
This commit refactors the config into a `main.Config` object instead of a global singleton. The `core.Service` is also refactored into the `main` package and individual pieces of the service are wired together by the `pilosa` binary. These two changes are required to begin to decouple packages from one another and allow them to be individually unit tested. Previously most top-level objects in the system could access any other top-level object through the `core.Service` which effectively made `Service` a singleton in the system. Each top-level object now has inline interfaces for their dependencies so that can be set at runtime by the `main` package or can be mocked by a test package.
27 lines
423 B
Go
27 lines
423 B
Go
package util
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/kr/s3/s3util"
|
|
)
|
|
|
|
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://")
|
|
}
|