feat(storage): FileStore interface abstraction + filesystem backend #134
Reference in New Issue
Block a user
Delete Branch "feat-storage-interface-filesystem"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Introduces a
FileStoreinterface to decouple the API layer from MinIO, and implements a local filesystem backend as an alternative storage option.Two commits, two issues:
Commit 1 — FileStore interface (#126)
Extracts the storage contract into a
FileStoreinterface so handlers work with any backend:FileStoreinterface ininternal/storage/interface.gowith 8 methods:Put,Get,GetVersion,Delete,Exists,Copy,PresignPut,PingExistsmethod to the MinIOStoragestruct (viaStatObject)Server.storageandServerState.storagenow holdstorage.FileStoreinstead of*storage.StorageStorageConfiggainsBackend("minio"/"filesystem") andFilesystem.RootDirfieldsmain.gouses a backend selection switch — defaults to"minio"for backward compatibilitystoreis declared asstorage.FileStoreso it stays a true nil when unconfigured (avoids the typed-nil-pointer-in-interface gotcha)Commit 2 — Filesystem backend (#127)
FilesystemStoreimplementingFileStorefor local disk:os.Rename— no partial files on crash/failurePutviaio.MultiWriterGet/GetVersionreturn*os.File(GetVersionignores versionID — no versioning on filesystem)Deleteis idempotent (no error if file already gone)Copyuses same atomic write patternPresignPutreturnsErrPresignNotSupported(handled by #129)Pingverifies root directory is writablemain.gobackend switchConfig
Or keep using MinIO (the default when
backendis omitted):Files changed
internal/storage/interface.goFileStoreinterfaceinternal/storage/filesystem.goFilesystemStoreimplementationinternal/storage/filesystem_test.gointernal/storage/storage.goExistsmethod + compile-time checkinternal/config/config.goBackend,FilesystemConfiginternal/api/handlers.goServer.storage→FileStoreinterfaceinternal/api/servermode.goServerState.storage→FileStoreinterfacecmd/silod/main.goconfig.example.yamlbackendfield + filesystem sectionTesting
go build ./...andgo vet ./...pass cleanly.Closes
Part of
Storage Migration: MinIO → PostgreSQL + Filesystem