mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-04 13:52:26 +08:00
fix: workdir path error
This commit is contained in:
@@ -135,10 +135,7 @@ type Config struct {
|
||||
func init() {
|
||||
// compatibility linux and windows
|
||||
var err error
|
||||
if gopath := os.Getenv("GOPATH"); gopath != "" {
|
||||
WorkDir = filepath.Join(gopath, "src", "github.com",
|
||||
"eiblog", "eiblog")
|
||||
}
|
||||
WorkDir = workDir()
|
||||
path := filepath.Join(WorkDir, "conf", "app.yml")
|
||||
|
||||
data, err := ioutil.ReadFile(path)
|
||||
|
||||
28
pkg/config/dev.go
Normal file
28
pkg/config/dev.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// +build !prod
|
||||
|
||||
// Package config provides ...
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// workDir recognize workspace dir
|
||||
var workDir = func() string {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for wd != "" {
|
||||
name := filepath.Join(wd, "conf")
|
||||
_, err := os.Stat(name)
|
||||
if err != nil {
|
||||
wd, _ = path.Split(wd)
|
||||
continue
|
||||
}
|
||||
return wd
|
||||
}
|
||||
return ""
|
||||
}
|
||||
7
pkg/config/pro.go
Normal file
7
pkg/config/pro.go
Normal file
@@ -0,0 +1,7 @@
|
||||
// +build prod
|
||||
|
||||
// Package config provides ...
|
||||
package config
|
||||
|
||||
// workDir production use current dir
|
||||
var workDir = func() string { return "" }
|
||||
Reference in New Issue
Block a user