123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- package conf
- import (
- "os"
- "os/exec"
- "path/filepath"
- "runtime"
- "strings"
- "sync"
- )
- func IsWindowsRuntime() bool {
- return runtime.GOOS == "windows"
- }
- func IsProdMode() bool {
- return strings.EqualFold(App.RunMode, "prod")
- }
- var (
- appPath string
- appPathOnce sync.Once
- )
- func AppPath() string {
- appPathOnce.Do(func() {
- var err error
- appPath, err = exec.LookPath(os.Args[0])
- if err != nil {
- panic("look executable path: " + err.Error())
- }
- appPath, err = filepath.Abs(appPath)
- if err != nil {
- panic("get absolute executable path: " + err.Error())
- }
- })
- return appPath
- }
- var (
- workDir string
- workDirOnce sync.Once
- )
- func WorkDir() string {
- workDirOnce.Do(func() {
- workDir = os.Getenv("GOGS_WORK_DIR")
- if workDir != "" {
- return
- }
- workDir = filepath.Dir(AppPath())
- })
- return workDir
- }
- var (
- customDir string
- customDirOnce sync.Once
- )
- func CustomDir() string {
- customDirOnce.Do(func() {
- customDir = os.Getenv("GOGS_CUSTOM")
- if customDir != "" {
- return
- }
- customDir = filepath.Join(WorkDir(), "custom")
- })
- return customDir
- }
- var (
- homeDir string
- homeDirOnce sync.Once
- )
- func HomeDir() string {
- homeDirOnce.Do(func() {
- homeDir = os.Getenv("HOME")
- if homeDir != "" {
- return
- }
- homeDir = os.Getenv("USERPROFILE")
- if homeDir != "" {
- return
- }
- homeDir = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
- })
- return homeDir
- }
|