others.go 968 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //go:build !windows
  2. // +build !windows
  3. package platform
  4. import (
  5. "os"
  6. "path/filepath"
  7. )
  8. func LineSeparator() string {
  9. return "\n"
  10. }
  11. // GetAssetLocation searches for `file` in the env dir, the executable dir, and certain locations
  12. func GetAssetLocation(file string) string {
  13. assetPath := NewEnvFlag(AssetLocation).GetValue(getExecutableDir)
  14. defPath := filepath.Join(assetPath, file)
  15. for _, p := range []string{
  16. defPath,
  17. filepath.Join("/usr/local/share/xray/", file),
  18. filepath.Join("/usr/share/xray/", file),
  19. filepath.Join("/opt/share/xray/", file),
  20. } {
  21. if _, err := os.Stat(p); os.IsNotExist(err) {
  22. continue
  23. }
  24. // asset found
  25. return p
  26. }
  27. // asset not found, let the caller throw out the error
  28. return defPath
  29. }
  30. // GetCertLocation searches for `file` in the env dir and the executable dir
  31. func GetCertLocation(file string) string {
  32. certPath := NewEnvFlag(CertLocation).GetValue(getExecutableDir)
  33. return filepath.Join(certPath, file)
  34. }