run.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package common
  2. import (
  3. "os"
  4. "path/filepath"
  5. "runtime"
  6. )
  7. //Get the currently selected configuration file directory
  8. //For non-Windows systems, select the /etc/nps as config directory if exist, or select ./
  9. //windows system, select the C:\Program Files\nps as config directory if exist, or select ./
  10. func GetRunPath() string {
  11. var path string
  12. if path = GetInstallPath(); !FileExists(path) {
  13. return GetAppPath()
  14. }
  15. return path
  16. }
  17. //Different systems get different installation paths
  18. func GetInstallPath() string {
  19. var path string
  20. if IsWindows() {
  21. path = `C:\Program Files\nps`
  22. } else {
  23. path = "/etc/nps"
  24. }
  25. return path
  26. }
  27. //Get the absolute path to the running directory
  28. func GetAppPath() string {
  29. if path, err := filepath.Abs(filepath.Dir(os.Args[0])); err == nil {
  30. return path
  31. }
  32. return os.Args[0]
  33. }
  34. //Determine whether the current system is a Windows system?
  35. func IsWindows() bool {
  36. if runtime.GOOS == "windows" {
  37. return true
  38. }
  39. return false
  40. }
  41. //interface log file path
  42. func GetLogPath() string {
  43. var path string
  44. if IsWindows() {
  45. path = filepath.Join(GetAppPath(), "nps.log")
  46. } else {
  47. path = "/var/log/nps.log"
  48. }
  49. return path
  50. }
  51. //interface npc log file path
  52. func GetNpcLogPath() string {
  53. var path string
  54. if IsWindows() {
  55. path = filepath.Join(GetAppPath(), "npc.log")
  56. } else {
  57. path = "/var/log/npc.log"
  58. }
  59. return path
  60. }
  61. //interface pid file path
  62. func GetTmpPath() string {
  63. var path string
  64. if IsWindows() {
  65. path = GetAppPath()
  66. } else {
  67. path = "/tmp"
  68. }
  69. return path
  70. }
  71. //config file path
  72. func GetConfigPath() string {
  73. var path string
  74. if IsWindows() {
  75. path = filepath.Join(GetAppPath(), "conf/npc.conf")
  76. } else {
  77. path = "conf/npc.conf"
  78. }
  79. return path
  80. }