Add interface

This commit is contained in:
Archie Fox
2025-03-12 22:37:08 +03:00
parent 46170ac5da
commit b16d0da418

View File

@@ -2,13 +2,17 @@ package account
import (
"encoding/json"
"password/files"
"strings"
"time"
"github.com/fatih/color"
)
type Db interface {
Read() ([]byte, error)
Write([]byte)
}
type Vault struct {
Accounts []Account `json:"accounts"`
UpdatedAt time.Time `json:"updatedAt"`
@@ -16,10 +20,10 @@ type Vault struct {
type VaultWithDb struct {
Vault
db files.JsonDb
db Db
}
func NewVault(db *files.JsonDb) *VaultWithDb {
func NewVault(db Db) *VaultWithDb {
file, err := db.Read()
if err != nil {
return &VaultWithDb{
@@ -27,7 +31,7 @@ func NewVault(db *files.JsonDb) *VaultWithDb {
Accounts: []Account{},
UpdatedAt: time.Now(),
},
db: *db,
db: db,
}
}
var vault Vault
@@ -39,12 +43,12 @@ func NewVault(db *files.JsonDb) *VaultWithDb {
Accounts: []Account{},
UpdatedAt: time.Now(),
},
db: *db,
db: db,
}
}
return &VaultWithDb{
Vault: vault,
db: *db,
db: db,
}
}