github.com/eagleql/xray-core@v1.4.4/common/platform/others.go (about) 1 // +build !windows 2 3 package platform 4 5 import ( 6 "os" 7 "path/filepath" 8 ) 9 10 func ExpandEnv(s string) string { 11 return os.ExpandEnv(s) 12 } 13 14 func LineSeparator() string { 15 return "\n" 16 } 17 18 func GetToolLocation(file string) string { 19 const name = "xray.location.tool" 20 toolPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableDir) 21 return filepath.Join(toolPath, file) 22 } 23 24 // GetAssetLocation search for `file` in certain locations 25 func GetAssetLocation(file string) string { 26 const name = "xray.location.asset" 27 assetPath := NewEnvFlag(name).GetValue(getExecutableDir) 28 defPath := filepath.Join(assetPath, file) 29 for _, p := range []string{ 30 defPath, 31 filepath.Join("/usr/local/share/xray/", file), 32 filepath.Join("/usr/share/xray/", file), 33 filepath.Join("/opt/share/xray/", file), 34 } { 35 if _, err := os.Stat(p); os.IsNotExist(err) { 36 continue 37 } 38 39 // asset found 40 return p 41 } 42 43 // asset not found, let the caller throw out the error 44 return defPath 45 }