Implement route rules
This commit is contained in:
35
constant/path.go
Normal file
35
constant/path.go
Normal 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)
|
||||
}
|
||||
}
|
||||
17
constant/path_unix.go
Normal file
17
constant/path_unix.go
Normal file
@@ -0,0 +1,17 @@
|
||||
//go:build unix
|
||||
|
||||
package constant
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
resourcePaths = append(resourcePaths, "/etc/config")
|
||||
resourcePaths = append(resourcePaths, "/usr/share")
|
||||
resourcePaths = append(resourcePaths, "/usr/local/etc/config")
|
||||
resourcePaths = append(resourcePaths, "/usr/local/share")
|
||||
if homeDir := os.Getenv("HOME"); homeDir != "" {
|
||||
resourcePaths = append(resourcePaths, homeDir+"/.local/share")
|
||||
}
|
||||
}
|
||||
7
constant/require.go
Normal file
7
constant/require.go
Normal file
@@ -0,0 +1,7 @@
|
||||
//go:build !go1.19
|
||||
|
||||
package constant
|
||||
|
||||
func init() {
|
||||
panic("sing-box requires Go 1.19 or later")
|
||||
}
|
||||
@@ -4,3 +4,8 @@ const (
|
||||
RuleTypeDefault = "default"
|
||||
RuleTypeLogical = "logical"
|
||||
)
|
||||
|
||||
const (
|
||||
LogicalTypeAnd = "and"
|
||||
LogicalTypeOr = "or"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user