diff options
Diffstat (limited to 'pkg/db')
| -rw-r--r-- | pkg/db/storage.go (renamed from pkg/db/client.go) | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/pkg/db/client.go b/pkg/db/storage.go index 4f43403..1c1c428 100644 --- a/pkg/db/client.go +++ b/pkg/db/storage.go @@ -12,15 +12,15 @@ import ( "github.com/xlgmokha/x/pkg/x" ) -type Paramable interface { - ToParam() string +type Entity interface { + Identifier() string } -type Storage[T Paramable] struct { +type Storage[T Entity] struct { dir string } -func New[T Paramable](dir string) *Storage[T] { +func New[T Entity](dir string) *Storage[T] { fullPath := x.Must(filepath.Abs(dir)) x.Check(os.MkdirAll(fullPath, 0700)) @@ -35,9 +35,10 @@ func (db *Storage[T]) Save(item T) error { if env.Fetch("DUMP", "") != "" { fmt.Println(w.String()) } - return ioutil.WriteFile( - fmt.Sprintf("%v/%v.yaml", db.dir, item.ToParam()), - w.Bytes(), - 0700, - ) + + return ioutil.WriteFile(db.filePathFor(item), w.Bytes(), 0700) +} + +func (db *Storage[T]) filePathFor(item T) string { + return fmt.Sprintf("%v/%v.yaml", db.dir, item.Identifier()) } |
