nps/lib/common/run.go

68 lines
1.3 KiB
Go
Raw Normal View History

2019-02-09 09:07:47 +00:00
package common
import (
"os"
"path/filepath"
"runtime"
)
//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 path = GetInstallPath(); !FileExists(path) {
2019-02-16 15:18:58 +00:00
return GetAppPath()
2019-02-09 09:07:47 +00:00
}
return path
}
//Different systems get different installation paths
func GetInstallPath() string {
var path string
if IsWindows() {
path = `C:\Program Files\nps`
} else {
path = "/etc/nps"
}
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 04:25:52 +00:00
path = filepath.Join(GetAppPath(), "nps.log")
2019-02-09 09:07:47 +00:00
} else {
2019-12-14 04:25:52 +00:00
path = "/var/log/nps.log"
2019-02-09 09:07:47 +00:00
}
return path
}
//interface pid file path
2019-02-12 19:54:00 +00:00
func GetTmpPath() string {
2019-02-09 09:07:47 +00:00
var path string
if IsWindows() {
2019-02-16 15:18:58 +00:00
path = GetAppPath()
2019-02-09 09:07:47 +00:00
} else {
path = "/tmp"
}
return path
}