mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-09 18:43:14 +00:00
Fix open cache file
This commit is contained in:
parent
5b3b74bd0f
commit
a2d43b3746
25
box.go
25
box.go
|
@ -213,6 +213,18 @@ func (s *Box) Start() error {
|
|||
}
|
||||
|
||||
func (s *Box) start() error {
|
||||
if s.clashServer != nil {
|
||||
err := s.clashServer.Start()
|
||||
if err != nil {
|
||||
return E.Cause(err, "start clash api server")
|
||||
}
|
||||
}
|
||||
if s.v2rayServer != nil {
|
||||
err := s.v2rayServer.Start()
|
||||
if err != nil {
|
||||
return E.Cause(err, "start v2ray api server")
|
||||
}
|
||||
}
|
||||
for i, out := range s.outbounds {
|
||||
if starter, isStarter := out.(common.Starter); isStarter {
|
||||
err := starter.Start()
|
||||
|
@ -243,18 +255,7 @@ func (s *Box) start() error {
|
|||
return E.Cause(err, "initialize inbound/", in.Type(), "[", tag, "]")
|
||||
}
|
||||
}
|
||||
if s.clashServer != nil {
|
||||
err = s.clashServer.Start()
|
||||
if err != nil {
|
||||
return E.Cause(err, "start clash api server")
|
||||
}
|
||||
}
|
||||
if s.v2rayServer != nil {
|
||||
err = s.v2rayServer.Start()
|
||||
if err != nil {
|
||||
return E.Cause(err, "start v2ray api server")
|
||||
}
|
||||
}
|
||||
|
||||
s.logger.Info("sing-box started (", F.Seconds(time.Since(s.createdAt).Seconds()), "s)")
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ type Server struct {
|
|||
urlTestHistory *urltest.HistoryStorage
|
||||
mode string
|
||||
storeSelected bool
|
||||
cacheFilePath string
|
||||
cacheFile adapter.ClashCacheFile
|
||||
}
|
||||
|
||||
|
@ -75,11 +76,7 @@ func NewServer(router adapter.Router, logFactory log.ObservableFactory, options
|
|||
} else {
|
||||
cachePath = C.BasePath(cachePath)
|
||||
}
|
||||
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{"*"},
|
||||
|
@ -118,6 +115,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")
|
||||
|
|
Loading…
Reference in a new issue