feat: 初始化配置中心项目

This commit is contained in:
2026-01-14 21:02:13 +08:00
commit 4436d3ee88
95 changed files with 8736 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
package client
import (
"encoding/json"
"os"
"path/filepath"
)
const cacheFile = "config-cache.json"
// Cache provides local file caching for configs
type Cache struct {
dir string
}
func NewCache(dir string) *Cache {
return &Cache{dir: dir}
}
func (c *Cache) Write(data map[string]interface{}) error {
path := filepath.Join(c.dir, cacheFile)
bytes, err := json.Marshal(data)
if err != nil {
return err
}
return os.WriteFile(path, bytes, 0644)
}
func (c *Cache) Read() (map[string]interface{}, error) {
path := filepath.Join(c.dir, cacheFile)
bytes, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var data map[string]interface{}
err = json.Unmarshal(bytes, &data)
return data, err
}