refactor: code refactor and improved context and error handling

This commit is contained in:
yusing
2025-05-24 10:02:24 +08:00
parent 1f1ae38e4d
commit 5b7c392297
31 changed files with 116 additions and 98 deletions

View File

@@ -2,12 +2,11 @@ package jsonstore
import (
"encoding/json"
"maps"
"os"
"path/filepath"
"reflect"
"maps"
"github.com/puzpuzpuz/xsync/v4"
"github.com/rs/zerolog/log"
"github.com/yusing/go-proxy/internal/common"
@@ -36,8 +35,10 @@ type store interface {
json.Unmarshaler
}
var stores = make(map[namespace]store)
var storesPath = common.DataDir
var (
stores = make(map[namespace]store)
storesPath = common.DataDir
)
func init() {
task.OnProgramExit("save_stores", func() {
@@ -117,7 +118,7 @@ func (s *MapStore[VT]) UnmarshalJSON(data []byte) error {
}
s.Map = xsync.NewMap[string, VT](xsync.WithPresize(len(tmp)))
for k, v := range tmp {
s.Map.Store(k, v)
s.Store(k, v)
}
return nil
}