mirror of https://github.com/ouqiang/gocron
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/ouqiang/gocron/modules/logger"
|
|
"runtime"
|
|
"github.com/ouqiang/gocron/modules/utils"
|
|
"gopkg.in/ini.v1"
|
|
)
|
|
|
|
var (
|
|
AppDir string // 应用根目录
|
|
ConfDir string // 配置目录
|
|
LogDir string // 日志目录
|
|
DataDir string // 存放session等
|
|
AppConfig string // 应用配置文件
|
|
Installed bool // 应用是否安装过
|
|
Setting *ini.Section // 应用配置
|
|
)
|
|
|
|
func InitEnv() {
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
logger.InitLogger()
|
|
wd, err := os.Getwd()
|
|
if err != nil {
|
|
logger.Fatal(err)
|
|
}
|
|
AppDir = wd
|
|
ConfDir = AppDir + "/conf"
|
|
LogDir = AppDir + "/log"
|
|
DataDir = AppDir + "/data"
|
|
AppConfig = ConfDir + "/app.ini"
|
|
checkDirExists(ConfDir, LogDir, DataDir)
|
|
Installed = IsInstalled()
|
|
}
|
|
|
|
// 判断应用是否安装过
|
|
func IsInstalled() bool {
|
|
_, err := os.Stat(ConfDir + "/install.lock")
|
|
if os.IsNotExist(err) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// 创建安装锁文件
|
|
func CreateInstallLock() error {
|
|
_, err := os.Create(ConfDir + "/install.lock")
|
|
if err != nil {
|
|
logger.Error("创建安装锁文件conf/install.lock失败")
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// 检测目录是否存在
|
|
func checkDirExists(path ...string) {
|
|
for _, value := range path {
|
|
if !utils.FileExist(value) {
|
|
logger.Fatal(value + "目录不存在或无权限访问")
|
|
}
|
|
}
|
|
} |