mirror of
https://github.com/smallnest/rpcx.git
synced 2025-09-26 20:21:14 +08:00
add CacheDiscovery
This commit is contained in:
@@ -3,6 +3,7 @@ package client
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -39,6 +40,15 @@ func CacheDiscovery(threshold int, cachedFile string, discovery ServiceDiscovery
|
||||
cachedFile = ".cache/discovery.json"
|
||||
}
|
||||
|
||||
cachedFileDir := filepath.Dir(cachedFile)
|
||||
|
||||
if _, err := os.Stat(cachedFileDir); os.IsNotExist(err) {
|
||||
// 目录不存在,创建目录
|
||||
if err := os.MkdirAll(cachedFileDir, os.ModePerm); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
return &cachedServiceDiscovery{
|
||||
threshold: threshold,
|
||||
cachedFile: cachedFile,
|
||||
|
Reference in New Issue
Block a user