mirror of
https://github.com/smallnest/rpcx.git
synced 2025-10-05 16:17:00 +08:00
add CacheDiscovery
This commit is contained in:
@@ -3,6 +3,7 @@ package client
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,6 +40,15 @@ func CacheDiscovery(threshold int, cachedFile string, discovery ServiceDiscovery
|
|||||||
cachedFile = ".cache/discovery.json"
|
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{
|
return &cachedServiceDiscovery{
|
||||||
threshold: threshold,
|
threshold: threshold,
|
||||||
cachedFile: cachedFile,
|
cachedFile: cachedFile,
|
||||||
|
Reference in New Issue
Block a user