diff --git a/storage/hashserver.go b/server/hashserver.go similarity index 99% rename from storage/hashserver.go rename to server/hashserver.go index 70a9a0f..dff338f 100644 --- a/storage/hashserver.go +++ b/server/hashserver.go @@ -1,4 +1,4 @@ -package storage +package server import ( "encoding/json" diff --git a/storage/inmemory_server.go b/server/inmemory_server.go similarity index 99% rename from storage/inmemory_server.go rename to server/inmemory_server.go index c2c9dab..3f56483 100644 --- a/storage/inmemory_server.go +++ b/server/inmemory_server.go @@ -1,4 +1,4 @@ -package storage +package server import ( "errors" diff --git a/storage/simple_server.go b/server/simple_server.go similarity index 89% rename from storage/simple_server.go rename to server/simple_server.go index 4c696b3..62a2c83 100644 --- a/storage/simple_server.go +++ b/server/simple_server.go @@ -1,4 +1,4 @@ -package storage +package server import ( "encoding/json" @@ -7,23 +7,20 @@ import ( "os" "path/filepath" + "git.nicholasnovak.io/nnovak/spatial-db/storage" "git.nicholasnovak.io/nnovak/spatial-db/world" ) const fileCacheSize = 8 -var ( - ChunkNotFoundError = errors.New("chunk was not found in storage") -) - type SimpleServer struct { StorageDir string - cache FileCache + cache storage.FileCache } func (s *SimpleServer) SetStorageRoot(path string) { s.StorageDir = path - s.cache = NewFileCache(256) + s.cache = storage.NewFileCache(256) } // Filesystem operations @@ -56,7 +53,7 @@ func (s *SimpleServer) FetchOrCreateChunk(pos world.ChunkPos) (world.ChunkData, } defer chunkFile.Close() - return ReadChunkFromFile(chunkFile) + return storage.ReadChunkFromFile(chunkFile) } // `FetchChunk' fetches the chunk's data, given the chunk's position @@ -68,13 +65,13 @@ func (s *SimpleServer) FetchChunk(pos world.ChunkPos) (world.ChunkData, error) { chunkFile, err := s.cache.FetchFile(chunkFileName) if err != nil { if errors.Is(err, fs.ErrNotExist) { - return chunkData, ChunkNotFoundError + return chunkData, storage.ChunkNotFoundError } else { return chunkData, err } } - return ReadChunkFromFile(chunkFile) + return storage.ReadChunkFromFile(chunkFile) } // Voxel server implementation diff --git a/storage/storage_server.go b/storage/storage_server.go index 80ab6bf..160db1b 100644 --- a/storage/storage_server.go +++ b/storage/storage_server.go @@ -1,6 +1,10 @@ package storage -import "git.nicholasnovak.io/nnovak/spatial-db/world" +import ( + "errors" + + "git.nicholasnovak.io/nnovak/spatial-db/world" +) type StorageServer interface { // Individual operations @@ -16,3 +20,7 @@ type StorageServer interface { // Network-level operations ReadChunkAt(pos world.ChunkPos) error } + +var ( + ChunkNotFoundError = errors.New("chunk was not found in storage") +)