ReAdjust the path of dev home.
This commit is contained in:
35
code/main/main.go
Normal file
35
code/main/main.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/eyebluecn/tank/code/config"
|
||||
"github.com/eyebluecn/tank/code/logger"
|
||||
"github.com/eyebluecn/tank/code/rest"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
//日志第一优先级保障
|
||||
logger.LOGGER.Init()
|
||||
defer logger.LOGGER.Destroy()
|
||||
|
||||
//装载配置文件,这个决定了是否需要执行安装过程
|
||||
config.CONFIG.Init()
|
||||
|
||||
//全局运行的上下文
|
||||
rest.CONTEXT.Init()
|
||||
defer rest.CONTEXT.Destroy()
|
||||
|
||||
http.Handle("/", rest.CONTEXT.Router)
|
||||
|
||||
logger.LOGGER.Info("App started at http://localhost:%v", config.CONFIG.ServerPort)
|
||||
|
||||
dotPort := fmt.Sprintf(":%v", config.CONFIG.ServerPort)
|
||||
err1 := http.ListenAndServe(dotPort, nil)
|
||||
if err1 != nil {
|
||||
log.Fatal("ListenAndServe: ", err1)
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -31,6 +32,22 @@ func GetGoPath() string {
|
||||
|
||||
}
|
||||
|
||||
//获取开发时的Home目录
|
||||
func GetDevHomePath() string {
|
||||
|
||||
_, file, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
panic("cannot get dev home path.")
|
||||
}
|
||||
|
||||
dir := GetDirOfPath(file)
|
||||
dir = GetDirOfPath(dir)
|
||||
dir = GetDirOfPath(dir)
|
||||
dir = GetDirOfPath(dir)
|
||||
|
||||
return dir
|
||||
}
|
||||
|
||||
//获取该应用可执行文件的位置。
|
||||
//例如:C:\Users\lishuang\AppData\Local\Temp
|
||||
func GetHomePath() string {
|
||||
@ -43,14 +60,14 @@ func GetHomePath() string {
|
||||
//如果exPath中包含了 /private/var/folders 我们认为是在Mac的开发环境中
|
||||
macDev := strings.HasPrefix(exPath, "/private/var/folders")
|
||||
if macDev {
|
||||
exPath = GetGoPath() + "/src/github.com/eyebluecn/tank/tmp"
|
||||
exPath = GetDevHomePath() + "/tmp"
|
||||
}
|
||||
|
||||
//如果exPath中包含了 \\AppData\\Local\\Temp 我们认为是在Win的开发环境中
|
||||
systemUser, err := user.Current()
|
||||
winDev := strings.HasPrefix(exPath, systemUser.HomeDir+"\\AppData\\Local\\Temp")
|
||||
if winDev {
|
||||
exPath = GetGoPath() + "/src/github.com/eyebluecn/tank/tmp"
|
||||
exPath = GetDevHomePath() + "/tmp"
|
||||
}
|
||||
|
||||
return exPath
|
||||
|
Reference in New Issue
Block a user