Fix open cache file

This commit is contained in:
世界
2023-03-05 11:05:30 +08:00
parent 06bc57d85a
commit 8550495789
2 changed files with 22 additions and 17 deletions

View File

@@ -45,6 +45,7 @@ type Server struct {
tcpListener net.Listener
mode string
storeSelected bool
cacheFilePath string
cacheFile adapter.ClashCacheFile
}
@@ -71,11 +72,7 @@ func NewServer(router adapter.Router, logFactory log.ObservableFactory, options
if cachePath == "" {
cachePath = "cache.db"
}
cacheFile, err := cachefile.Open(cachePath)
if err != nil {
return nil, E.Cause(err, "open cache file")
}
server.cacheFile = cacheFile
server.cacheFilePath = cachePath
}
cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
@@ -113,6 +110,13 @@ func NewServer(router adapter.Router, logFactory log.ObservableFactory, options
}
func (s *Server) Start() error {
if s.cacheFilePath != "" {
cacheFile, err := cachefile.Open(s.cacheFilePath)
if err != nil {
return E.Cause(err, "open cache file")
}
s.cacheFile = cacheFile
}
listener, err := net.Listen("tcp", s.httpServer.Addr)
if err != nil {
return E.Cause(err, "external controller listen error")