Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qwenode committed Apr 25, 2024
1 parent 358042e commit bff25b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions fsdb/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fsdb

import (
"encoding/json"
"github.com/qwenode/gogo/file"
"github.com/qwenode/gogo/ff"
"github.com/qwenode/gogo/serialize"
"sync"
)
Expand All @@ -25,22 +25,22 @@ func (r *Common[T]) SetData(data T) {
}

func (r *Common[T]) Save() error {
r.lock.RLock()
defer r.lock.RUnlock()
return file.PutContents(r.filename, serialize.JsonEncodeByte(r.data))
r.lock.Lock()
defer r.lock.Unlock()
return ff.PutContents(r.filename, serialize.JsonEncodeByte(r.data))
}
func (r *Common[T]) Reload() error {
r.lock.Lock()
defer r.lock.Unlock()
if !file.Exist(r.filename) {
if !ff.Exist(r.filename) {
return nil
}
return json.Unmarshal(file.GetContentsByte(r.filename), &r.data)
return json.Unmarshal(ff.GetContentsByte(r.filename), &r.data)
}
func (r *Common[T]) SaveTo(path string) error {
r.lock.RLock()
defer r.lock.RUnlock()
return file.PutContents(path, serialize.JsonEncodeByte(r.data))
r.lock.Lock()
defer r.lock.Unlock()
return ff.PutContents(path, serialize.JsonEncodeByte(r.data))
}
func CommonFromFile[T any](filename string) *Common[T] {
s := new(Common[T])
Expand Down
18 changes: 9 additions & 9 deletions fsdb/maplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fsdb
import (
"encoding/json"
"errors"
"github.com/qwenode/gogo/file"
"github.com/qwenode/gogo/ff"
"github.com/qwenode/gogo/serialize"
"sync"
)
Expand Down Expand Up @@ -31,10 +31,10 @@ func (r *MapList[T]) GetDataCopy() map[string]T {
func (r *MapList[T]) Reload() error {
r.lock.Lock()
defer r.lock.Unlock()
if !file.Exist(r.filename) {
if !ff.Exist(r.filename) {
return errors.New("file not found")
}
return json.Unmarshal(file.GetContentsByte(r.filename), &r.data)
return json.Unmarshal(ff.GetContentsByte(r.filename), &r.data)
}
func (r *MapList[T]) Add(key string, item T) {
r.lock.Lock()
Expand All @@ -61,14 +61,14 @@ func (r *MapList[T]) Get(key string) (T, bool) {
return t, ok
}
func (r *MapList[T]) Save() error {
r.lock.RLock()
defer r.lock.RUnlock()
return file.PutContents(r.filename, serialize.JsonEncodeByte(r.data))
r.lock.Lock()
defer r.lock.Unlock()
return ff.PutContents(r.filename, serialize.JsonEncodeByte(r.data))
}
func (r *MapList[T]) SaveTo(path string) error {
r.lock.RLock()
defer r.lock.RUnlock()
return file.PutContents(path, serialize.JsonEncodeByte(r.data))
r.lock.Lock()
defer r.lock.Unlock()
return ff.PutContents(path, serialize.JsonEncodeByte(r.data))
}
func (r *MapList[T]) Len() int {
r.lock.RLock()
Expand Down

0 comments on commit bff25b0

Please sign in to comment.