Skip to content

Commit

Permalink
refactor: dirname in compile wrong.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvgamerr committed May 10, 2023
1 parent 0c4a51c commit 758b996
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# DEBUG=debug
DEBUG=debug
5 changes: 2 additions & 3 deletions act/act.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ var IsDebug bool = false
var IsDev bool = false

func init() {
if err := goenv.Load(); err == nil {
IsDev = true
}
goenv.Load()
IsDev = os.Getenv(DEBUG) != ""
IsDebug = os.Getenv(DEBUG) != "" && os.Getenv(DEBUG) != "production"
}

Expand Down
27 changes: 13 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"hoyolab/act"

"github.com/go-resty/resty/v2"
"github.com/tmilewski/goenv"
"github.com/zellyn/kooky"
"github.com/zellyn/kooky/browser/chrome"
)
Expand All @@ -25,30 +26,28 @@ var logPath string = ""
var logfile *os.File

func init() {
goenv.Load()
IsDev := os.Getenv(act.DEBUG) != ""

execFilename, err := os.Executable()
if err != nil {
log.Fatal(err)
}
baseFilename := strings.ReplaceAll(filepath.Base(execFilename), filepath.Ext(execFilename), "")
dirname := filepath.Dir(execFilename)

configPath = fmt.Sprintf("%s.%s", baseFilename, configExt)
logPath = fmt.Sprintf("%s.%s", baseFilename, logExt)

dirname, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
if IsDev {
dirname, err = os.UserHomeDir()
if err != nil {
log.Fatal(err)
}
}

if !act.IsDev {
dirname = filepath.Dir(execFilename)
}
configPath = path.Join(dirname, fmt.Sprintf("%s.%s", baseFilename, configExt))
logPath = path.Join(dirname, fmt.Sprintf("%s.%s", baseFilename, logExt))

if _, err := os.Stat(path.Join(dirname, configExt)); err == nil {
configPath = path.Join(dirname, configPath)
logPath = path.Join(dirname, logPath)
}
log.SetFlags(log.Lshortfile | log.Ltime)
if !act.IsDev {
if !IsDev {
log.SetFlags(log.Ldate | log.Ltime)
f, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
Expand Down

0 comments on commit 758b996

Please sign in to comment.