Merge pull request #94 from fkautz/pr_out_refactoring_file_storage_driver_to_fsstorage

master
Frederick F. Kautz IV 10 years ago
commit c2917f0d64
  1. 4
      pkgs/gateway/gateway.go
  2. 8
      pkgs/storage/fsstorage/fs_storage.go
  3. 4
      pkgs/storage/fsstorage/fs_storage_test.go
  4. 14
      pkgs/storage/storage.go
  5. 7
      pkgs/storage/storage_test.go

@ -8,7 +8,7 @@ import (
"path" "path"
"github.com/gorilla/mux" "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" "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) { func SimpleFileStorageDriver(bucket string, input chan ObjectRequest, config GatewayConfig) {
fileStorage := storage.FileStorage{ fileStorage := fsstorage.FileSystemStorage{
RootDir: config.dataDir, RootDir: config.dataDir,
} }
for request := range input { for request := range input {

@ -1,4 +1,4 @@
package storage package fsstorage
import ( import (
"io/ioutil" "io/ioutil"
@ -7,16 +7,16 @@ import (
"path/filepath" "path/filepath"
) )
type FileStorage struct { type FileSystemStorage struct {
RootDir string 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)) 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) os.MkdirAll(filepath.Dir(path.Join(storage.RootDir, objectPath)), 0700)
return ioutil.WriteFile(path.Join(storage.RootDir, objectPath), object, 0600) return ioutil.WriteFile(path.Join(storage.RootDir, objectPath), object, 0600)
} }

@ -1,4 +1,4 @@
package storage package fsstorage
import ( import (
. "gopkg.in/check.v1" . "gopkg.in/check.v1"
@ -6,7 +6,7 @@ import (
"os" "os"
) )
type FileStorageSuite struct{} type FileSystemStorageSuite struct{}
var _ = Suite(&FileStorageSuite{}) var _ = Suite(&FileStorageSuite{})

@ -1,20 +1,6 @@
package storage package storage
import (
"fmt"
"github.com/gorilla/mux"
"net/http"
)
type ObjectStorage interface { type ObjectStorage interface {
Get(path string) ([]byte, error) Get(path string) ([]byte, error)
Put(path string, object []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 package storage
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
@ -9,7 +10,7 @@ import (
) )
func TestPrintsStorage(t *testing.T) { func TestPrintsStorage(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(StorageHandler)) server := httptest.NewServer(http.HandlerFunc(storageHandler))
defer server.Close() defer server.Close()
res, err := http.Get(server.URL) res, err := http.Get(server.URL)
if err != nil { if err != nil {
@ -25,3 +26,7 @@ func TestPrintsStorage(t *testing.T) {
log.Fatal("Expected 'Storage', Received '" + bodyString + "'") log.Fatal("Expected 'Storage', Received '" + bodyString + "'")
} }
} }
func storageHandler(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "Storage")
}

Loading…
Cancel
Save