summaryrefslogtreecommitdiff
path: root/internal/types
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-05-27 09:20:49 +0300
committerPaul Buetow <paul@buetow.org>2024-05-27 09:20:49 +0300
commit11788abad75c0d4920ed4f7797febd7d36569a66 (patch)
tree1432a50e82c5db81c1c2d33461a7c25ebacc258a /internal/types
parent9be6694a4a70e06be713033145f763e9d7f86295 (diff)
move the interface to the client
Diffstat (limited to 'internal/types')
-rw-r--r--internal/types/entry.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/internal/types/entry.go b/internal/types/entry.go
index af1e991..eca7b91 100644
--- a/internal/types/entry.go
+++ b/internal/types/entry.go
@@ -10,6 +10,11 @@ import (
"codeberg.org/snonux/gos/internal/vfs"
)
+type fs interface {
+ ReadFile(name string) ([]byte, error)
+ WriteFile(filePath string, bytes []byte) error
+}
+
// Tells me whether the entry was shared to the sm platform named Name
type Shared struct {
Name string `json:"name"`
@@ -37,7 +42,7 @@ type Entry struct {
Body string `json:"body"`
Shared []Shared `json:"shared,omitempty"`
Epoch int `json:"epoch,omitempty"`
- vfs vfs.VFS
+ fs fs
// The checksum of the whole entry, can change depending on the state.
checksum string
@@ -57,23 +62,23 @@ func NewEntry(bytes []byte) (Entry, error) {
return e, nil
}
-func NewEntryFromFile(filePath string, vfsToUse ...vfs.VFS) (Entry, error) {
+func NewEntryFromFile(filePath string, fsToUse ...fs) (Entry, error) {
var (
bytes []byte
err error
- vfs vfs.VFS = vfs.RealFS{}
+ fs fs = vfs.RealFS{}
)
- if len(vfsToUse) > 0 {
- vfs = vfsToUse[0]
+ if len(fsToUse) > 0 {
+ fs = fsToUse[0]
}
- bytes, err = vfs.ReadFile(filePath)
+ bytes, err = fs.ReadFile(filePath)
if err != err {
return Entry{}, err
}
e, err := NewEntry(bytes)
- e.vfs = vfs
+ e.fs = fs
return e, err
}
@@ -86,7 +91,7 @@ func NewEntryFromCopy(other Entry) (Entry, error) {
func (e *Entry) initialize() {
e.mu = &sync.Mutex{}
e.checksumDirty = true
- e.vfs = vfs.RealFS{}
+ e.fs = vfs.RealFS{}
}
func (e Entry) Equals(other Entry) bool {
@@ -170,7 +175,7 @@ func (e Entry) SaveFile(filePath string) error {
return err
}
- return e.vfs.WriteFile(filePath, jsonStr)
+ return e.fs.WriteFile(filePath, jsonStr)
}
func (e Entry) String() string {