Migration: go1.21

This commit is contained in:
Dreamacro
2023-08-13 21:44:16 +08:00
parent e5668687ab
commit cb8c732375
10 changed files with 22 additions and 26 deletions

View File

@ -9,13 +9,9 @@ import (
"github.com/Dreamacro/clash/log"
)
var printMarkWarnOnce sync.Once
func printMarkWarn() {
printMarkWarnOnce.Do(func() {
log.Warnln("Routing mark on socket is not supported on current platform")
})
}
var printMarkWarn = sync.OnceFunc(func() {
log.Warnln("Routing mark on socket is not supported on current platform")
})
func bindMarkToDialer(mark int, dialer *net.Dialer, _ string, _ net.IP) {
printMarkWarn()

View File

@ -13,9 +13,7 @@ import (
)
var (
initOnce sync.Once
fileMode os.FileMode = 0o666
defaultCache *CacheFile
fileMode os.FileMode = 0o666
bucketSelected = []byte("selected")
bucketFakeip = []byte("fakeip")
@ -136,7 +134,8 @@ func (c *CacheFile) Close() error {
return c.DB.Close()
}
func initCache() {
// Cache return singleton of CacheFile
var Cache = sync.OnceValue(func() *CacheFile {
options := bbolt.Options{Timeout: time.Second}
db, err := bbolt.Open(C.Path.Cache(), fileMode, &options)
switch err {
@ -152,14 +151,7 @@ func initCache() {
log.Warnln("[CacheFile] can't open cache file: %s", err.Error())
}
defaultCache = &CacheFile{
return &CacheFile{
DB: db,
}
}
// Cache return singleton of CacheFile
func Cache() *CacheFile {
initOnce.Do(initCache)
return defaultCache
}
})