refactor: 客户端目录统一添加 kenaito-conf- 前缀
- go-client → kenaito-conf-go-client - python-client → kenaito-conf-python-client - python-client-demo → kenaito-conf-python-client-demo - nodejs-client → kenaito-conf-nodejs-client - nodejs-client-demo → kenaito-conf-nodejs-client-demo - 更新所有 README 和 package.json 中的路径引用
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user