mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Refactoring file storage driver to fsstorage
This commit is contained in:
parent
8a5b8ac90f
commit
0cf80e075e
@ -8,7 +8,7 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/minio-io/minio/pkgs/storage"
|
||||
"github.com/minio-io/minio/pkgs/storage/fsstorage"
|
||||
"github.com/tchap/go-patricia/patricia"
|
||||
)
|
||||
|
||||
@ -197,7 +197,7 @@ func InMemoryStorageDriver(bucket string, input chan ObjectRequest, config Gatew
|
||||
}
|
||||
|
||||
func SimpleFileStorageDriver(bucket string, input chan ObjectRequest, config GatewayConfig) {
|
||||
fileStorage := storage.FileStorage{
|
||||
fileStorage := fsstorage.FileSystemStorage{
|
||||
RootDir: config.dataDir,
|
||||
}
|
||||
for request := range input {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package storage
|
||||
package fsstorage
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
@ -7,16 +7,16 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type FileStorage struct {
|
||||
type FileSystemStorage struct {
|
||||
RootDir string
|
||||
}
|
||||
|
||||
func (storage FileStorage) Get(objectPath string) ([]byte, error) {
|
||||
func (storage FileSystemStorage) Get(objectPath string) ([]byte, error) {
|
||||
return ioutil.ReadFile(path.Join(storage.RootDir, objectPath))
|
||||
|
||||
}
|
||||
|
||||
func (storage FileStorage) Put(objectPath string, object []byte) error {
|
||||
func (storage FileSystemStorage) Put(objectPath string, object []byte) error {
|
||||
os.MkdirAll(filepath.Dir(path.Join(storage.RootDir, objectPath)), 0700)
|
||||
return ioutil.WriteFile(path.Join(storage.RootDir, objectPath), object, 0600)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package storage
|
||||
package fsstorage
|
||||
|
||||
import (
|
||||
. "gopkg.in/check.v1"
|
||||
@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type FileStorageSuite struct{}
|
||||
type FileSystemStorageSuite struct{}
|
||||
|
||||
var _ = Suite(&FileStorageSuite{})
|
||||
|
@ -1,20 +1,6 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ObjectStorage interface {
|
||||
Get(path string) ([]byte, error)
|
||||
Put(path string, object []byte) error
|
||||
}
|
||||
|
||||
func RegisterStorageHandlers(router *mux.Router) {
|
||||
router.HandleFunc("/storage/rpc", StorageHandler)
|
||||
}
|
||||
|
||||
func StorageHandler(w http.ResponseWriter, req *http.Request) {
|
||||
fmt.Fprintf(w, "Storage")
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -9,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestPrintsStorage(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(StorageHandler))
|
||||
server := httptest.NewServer(http.HandlerFunc(storageHandler))
|
||||
defer server.Close()
|
||||
res, err := http.Get(server.URL)
|
||||
if err != nil {
|
||||
@ -25,3 +26,7 @@ func TestPrintsStorage(t *testing.T) {
|
||||
log.Fatal("Expected 'Storage', Received '" + bodyString + "'")
|
||||
}
|
||||
}
|
||||
|
||||
func storageHandler(w http.ResponseWriter, req *http.Request) {
|
||||
fmt.Fprintf(w, "Storage")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user