1 Star 0 Fork 23

Ryouj/GO-OAM

forked from charles.zhang/GO-OAM 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 2.46 KB
一键复制 编辑 原始数据 按行查看 历史
charles.zhang 提交于 2024-04-19 09:15 . update readme
package main
import (
"OAM/conf"
"OAM/controllers"
"OAM/models"
_ "OAM/routers"
fn "OAM/util"
"fmt"
"syscall"
"errors"
"os"
"path/filepath"
"github.com/beego/beego/v2/core/logs"
beego "github.com/beego/beego/v2/server/web"
jsoniter "github.com/json-iterator/go"
)
func main() {
initLog()
go initGlobalCfg()
storePath := beego.AppConfig.DefaultString("store_path", "")
if storePath == "" {
storePath, err := fn.UserHomeDir()
if err != nil {
panic(err)
}
conf.GlobalCfg.DATA_STORE_PATH = filepath.Join(storePath, "/.oam")
} else {
conf.GlobalCfg.DATA_STORE_PATH = storePath
}
if !fn.FileIsExists(conf.GlobalCfg.DATA_STORE_PATH) {
os.MkdirAll(conf.GlobalCfg.DATA_STORE_PATH, os.ModePerm)
}
beego.SetStaticPath(conf.STATIC_EXT_BASE_URL, conf.GlobalCfg.DATA_STORE_PATH)
beego.ErrorController(&controllers.ErrorController{})
beego.AddFuncMap("json", func(in interface{}) (string, error) {
return jsoniter.MarshalToString(in)
})
beego.Run()
}
//初始配置日志组件
func initLog() {
isDebug, _ := beego.AppConfig.Bool("debug")
if !isDebug {
err := logs.SetLogger(logs.AdapterFile, `{"filename":"logs/opsdoc.log","level":6,"maxdays":10,"daily":true}`)
if err != nil {
panic(err)
}
logs.EnableFuncCallDepth(true)
logs.Async(1e3)
}
}
// 初始一些通用配置
func initGlobalCfg() {
var err error
//当前程序工作目录
workDir, err := os.Getwd()
if err != nil {
panic(err)
}
//conf.GlobalCfg.WORK_PATH = workDir
// 缓存引擎类型
conf.GlobalCfg.CACHE_TYPE = beego.AppConfig.DefaultString("cache_type", "memory")
// 加载RSA密钥文件
logs.Info("加载密钥文件")
priKeyPath := filepath.Join(workDir, "conf", "pri.pem")
conf.GlobalCfg.RSA_DEFAULT_PRIVATE_KEY, err = fn.LoadPrivateKeyFromFile(priKeyPath)
if err != nil {
panic(errors.New("加载私钥文件失败"))
}
pubKeyPath := filepath.Join(workDir, "conf", "pub.pem")
conf.GlobalCfg.RSA_DEFAULT_PUBLIC_KEY, err = fn.LoadPublicKeyFromFile(pubKeyPath)
if err != nil {
panic(errors.New("加载公钥文件失败"))
}
//初始AES密钥
conf.GlobalCfg.SYMMETRIC_KEY = models.InitSymmetrickey()
}
func restart() {
fmt.Println("重启程序...")
// 获取当前可执行文件的路径
exePath, err := os.Executable()
if err != nil {
fmt.Println("无法获取可执行文件路径:", err)
return
}
// 使用 syscall.Exec 来替换当前进程
err = syscall.Exec(exePath, os.Args, os.Environ())
if err != nil {
fmt.Println("重启失败:", err)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ryouj/OAM.git
git@gitee.com:ryouj/OAM.git
ryouj
OAM
GO-OAM
master

搜索帮助