Implement route rules

This commit is contained in:
世界
2022-07-02 22:55:10 +08:00
parent 7c57eb70e8
commit 6eae8e361f
40 changed files with 1220 additions and 145 deletions

35
constant/path.go Normal file
View File

@@ -0,0 +1,35 @@
package constant
import (
"os"
"path/filepath"
"github.com/sagernet/sing/common/rw"
)
const dirName = "sing-box"
var resourcePaths []string
func Find(name string) (string, bool) {
name = os.ExpandEnv(name)
if rw.FileExists(name) {
return name, true
}
for _, dir := range resourcePaths {
if path := filepath.Join(dir, dirName, name); rw.FileExists(path) {
return path, true
}
}
return name, false
}
func init() {
resourcePaths = append(resourcePaths, ".")
if userConfigDir, err := os.UserConfigDir(); err == nil {
resourcePaths = append(resourcePaths, userConfigDir)
}
if userCacheDir, err := os.UserCacheDir(); err == nil {
resourcePaths = append(resourcePaths, userCacheDir)
}
}