From 0cf80e075e8f53bacbd8efbeaa12636d1ae8bed3 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Mon, 8 Dec 2014 14:25:57 -0800 Subject: [PATCH] Refactoring file storage driver to fsstorage --- pkgs/gateway/gateway.go | 4 ++-- .../{file_storage.go => fsstorage/fs_storage.go} | 8 ++++---- .../fs_storage_test.go} | 4 ++-- pkgs/storage/storage.go | 14 -------------- pkgs/storage/storage_test.go | 7 ++++++- 5 files changed, 14 insertions(+), 23 deletions(-) rename pkgs/storage/{file_storage.go => fsstorage/fs_storage.go} (59%) rename pkgs/storage/{file_storage_test.go => fsstorage/fs_storage_test.go} (95%) diff --git a/pkgs/gateway/gateway.go b/pkgs/gateway/gateway.go index 0025b0550..61ae86b3b 100644 --- a/pkgs/gateway/gateway.go +++ b/pkgs/gateway/gateway.go @@ -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 { diff --git a/pkgs/storage/file_storage.go b/pkgs/storage/fsstorage/fs_storage.go similarity index 59% rename from pkgs/storage/file_storage.go rename to pkgs/storage/fsstorage/fs_storage.go index 46b832a45..5d32260a6 100644 --- a/pkgs/storage/file_storage.go +++ b/pkgs/storage/fsstorage/fs_storage.go @@ -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) } diff --git a/pkgs/storage/file_storage_test.go b/pkgs/storage/fsstorage/fs_storage_test.go similarity index 95% rename from pkgs/storage/file_storage_test.go rename to pkgs/storage/fsstorage/fs_storage_test.go index 9f1116f90..5419cef47 100644 --- a/pkgs/storage/file_storage_test.go +++ b/pkgs/storage/fsstorage/fs_storage_test.go @@ -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{}) diff --git a/pkgs/storage/storage.go b/pkgs/storage/storage.go index 14ff348de..03a99dcaf 100644 --- a/pkgs/storage/storage.go +++ b/pkgs/storage/storage.go @@ -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") -} diff --git a/pkgs/storage/storage_test.go b/pkgs/storage/storage_test.go index 8f8492a15..816efa457 100644 --- a/pkgs/storage/storage_test.go +++ b/pkgs/storage/storage_test.go @@ -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") +}