Skip to content

Commit

Permalink
add CacheDiscovery
Browse files Browse the repository at this point in the history
  • Loading branch information
smallnest committed Oct 31, 2023
1 parent 39c51c0 commit b73eba8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions client/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"encoding/json"
"os"
"path/filepath"
"sync"
)

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b73eba8

Please sign in to comment.