Files

107 lines
1.9 KiB
Go
Raw Permalink Normal View History

2019-02-09 17:07:47 +08:00
package common
import (
"os"
"path/filepath"
"runtime"
)
var ConfPath string
2019-02-09 17:07:47 +08:00
//Get the currently selected configuration file directory
//For non-Windows systems, select the /etc/nps as config directory if exist, or select ./
//windows system, select the C:\Program Files\nps as config directory if exist, or select ./
func GetRunPath() string {
var path string
if len(os.Args) == 1 {
if !IsWindows() {
dir, _ := filepath.Abs(filepath.Dir(os.Args[0])) //返回
return dir + "/"
} else {
return "./"
}
2022-10-31 10:40:47 +08:00
} else {
if path = GetInstallPath(); !FileExists(path) {
return GetAppPath()
}
2019-02-09 17:07:47 +08:00
}
return path
}
//Different systems get different installation paths
func GetInstallPath() string {
var path string
if ConfPath != "" {
return ConfPath
}
2022-10-30 00:36:03 +08:00
if IsWindows() {
path = `C:\Program Files\nps`
} else {
path = "/etc/nps"
}
2019-02-09 17:07:47 +08:00
return path
}
//Get the absolute path to the running directory
func GetAppPath() string {
if path, err := filepath.Abs(filepath.Dir(os.Args[0])); err == nil {
return path
}
return os.Args[0]
}
//Determine whether the current system is a Windows system?
func IsWindows() bool {
if runtime.GOOS == "windows" {
return true
}
return false
}
//interface log file path
func GetLogPath() string {
var path string
if IsWindows() {
2019-12-14 12:25:52 +08:00
path = filepath.Join(GetAppPath(), "nps.log")
2019-02-09 17:07:47 +08:00
} else {
2019-12-14 12:25:52 +08:00
path = "/var/log/nps.log"
2019-02-09 17:07:47 +08:00
}
return path
}
2019-12-16 02:28:31 +08:00
//interface npc log file path
func GetNpcLogPath() string {
var path string
if IsWindows() {
path = filepath.Join(GetAppPath(), "npc.log")
} else {
path = "/var/log/npc.log"
}
return path
}
2019-02-09 17:07:47 +08:00
//interface pid file path
2019-02-13 03:54:00 +08:00
func GetTmpPath() string {
2019-02-09 17:07:47 +08:00
var path string
if IsWindows() {
2019-02-16 23:18:58 +08:00
path = GetAppPath()
2019-02-09 17:07:47 +08:00
} else {
path = "/tmp"
}
return path
}
//config file path
func GetConfigPath() string {
var path string
if IsWindows() {
path = filepath.Join(GetAppPath(), "conf/npc.conf")
} else {
path = "conf/npc.conf"
}
return path
}