Make gogs possible to run with debugger on Windows

pull/6511/head
Linquize 2021-02-28 20:39:57 +08:00
parent 09d0d07353
commit 50a24e5839
1 changed files with 12 additions and 3 deletions

View File

@ -7,6 +7,7 @@ package conf
import (
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
@ -34,9 +35,17 @@ var (
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())
lookPath := true
if os.PathSeparator == '\\' {
appPath = strings.ReplaceAll(os.Args[0], "\\", "/")
file := path.Base(appPath)
lookPath = file != "__debug_bin"
}
if lookPath {
appPath, err = exec.LookPath(os.Args[0])
if err != nil {
panic("look executable path: " + err.Error())
}
}
appPath, err = filepath.Abs(appPath)