probe/config/path.go

80 lines
1.4 KiB
Go
Raw Normal View History

2018-04-18 14:56:13 +00:00
package config
import (
"fmt"
"os"
"path"
"path/filepath"
2018-04-20 11:19:14 +00:00
"log"
"os/user"
2018-04-26 08:39:32 +00:00
occn "git.loafle.net/overflow/commons-go/config/noauthprobe"
occp "git.loafle.net/overflow/commons-go/config/probe"
2018-04-18 14:56:13 +00:00
)
var (
rootDir string
)
func init() {
exePath, err := os.Executable()
if err != nil {
panic(err)
}
binDir := filepath.Dir(exePath)
if "debug" == filepath.Base(exePath) {
rootDir = path.Join(binDir, "_build")
2018-04-20 11:19:14 +00:00
} else if "/tmp" == binDir {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
rootDir = path.Join(usr.HomeDir, "/go/src/git.loafle.net/overflow/probe/_build")
2018-04-18 14:56:13 +00:00
} else {
rootDir = filepath.Clean(fmt.Sprintf("%s/..", binDir))
}
}
func RootDir() string {
return rootDir
}
func BinDir() string {
2018-04-26 08:39:32 +00:00
return path.Join(RootDir(), occp.PathBin)
2018-04-18 14:56:13 +00:00
}
func ConfigDir() string {
2018-04-26 08:39:32 +00:00
return path.Join(RootDir(), occp.PathConfig)
2018-04-18 14:56:13 +00:00
}
func JREDir() string {
2018-04-26 08:39:32 +00:00
return path.Join(RootDir(), occp.PathJRE)
2018-04-18 14:56:13 +00:00
}
func JavaBinPath() string {
return path.Join(JREDir(), "bin", "java")
}
func LogsDir() string {
2018-04-26 08:39:32 +00:00
return path.Join(RootDir(), occp.PathLogs)
2018-04-18 14:56:13 +00:00
}
func PIDDir() string {
2018-04-26 08:39:32 +00:00
return path.Join(RootDir(), occp.PathPID)
2018-04-18 14:56:13 +00:00
}
func ProbeConfigFilePath() string {
2018-04-26 08:39:32 +00:00
return path.Join(BinDir(), occp.ConfigFileName)
2018-04-18 14:56:13 +00:00
}
func ProbeLoggingConfigFilePath() string {
2018-04-26 08:39:32 +00:00
return path.Join(BinDir(), occp.LoggingConfigFileName)
2018-04-18 14:56:13 +00:00
}
func NoAuthProbeConfigFilePath() string {
2018-04-26 08:39:32 +00:00
return path.Join(BinDir(), occn.ConfigFileName)
2018-04-18 14:56:13 +00:00
}