From df2a128e1b136d6b30a2e0ebe51fc2d0e12ee39e Mon Sep 17 00:00:00 2001 From: Nicholas Novak <34256932+NickyBoy89@users.noreply.github.com> Date: Fri, 8 Dec 2023 19:30:19 -0800 Subject: [PATCH] refactor: Moved the servers to their separate directories --- {storage => server}/hashserver.go | 2 +- {storage => server}/inmemory_server.go | 2 +- {storage => server}/simple_server.go | 17 +++++++---------- storage/storage_server.go | 10 +++++++++- 4 files changed, 18 insertions(+), 13 deletions(-) rename {storage => server}/hashserver.go (99%) rename {storage => server}/inmemory_server.go (99%) rename {storage => server}/simple_server.go (89%) 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") +)