mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
【优化】租户功能,框架优化
This commit is contained in:
73
main.go
73
main.go
@@ -1,28 +1,65 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"pandax/apps/job/jobs"
|
||||
"pandax/base/config"
|
||||
"pandax/base/ctx"
|
||||
"pandax/base/global"
|
||||
"pandax/base/logger"
|
||||
"pandax/base/starter"
|
||||
"pandax/initialize"
|
||||
"pandax/middleware"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/initialize"
|
||||
"pandax/pkg/middleware"
|
||||
)
|
||||
|
||||
func main() {
|
||||
global.Db = starter.GormInit(config.Conf.Server.DbType)
|
||||
initialize.InitTable()
|
||||
// gin前置 函数
|
||||
ctx.UseAfterHandlerInterceptor(middleware.OperationHandler)
|
||||
// gin前置 函数
|
||||
ctx.UseBeforeHandlerInterceptor(ctx.PermissionHandler)
|
||||
// gin后置 函数
|
||||
ctx.UseAfterHandlerInterceptor(ctx.LogHandler)
|
||||
go func() {
|
||||
// 启动系统调度任务
|
||||
jobs.InitJob()
|
||||
jobs.Setup()
|
||||
}()
|
||||
starter.RunWebServer(initialize.InitRouter())
|
||||
var (
|
||||
configFile string
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "panda is the main component in the panda.",
|
||||
Short: `panda is go gin frame`,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if configFile != "" {
|
||||
global.Conf = config.InitConfig(configFile)
|
||||
global.Log = logger.InitLog(global.Conf.Log)
|
||||
global.Db = starter.GormInit(global.Conf.Server.DbType)
|
||||
initialize.InitTable()
|
||||
} else {
|
||||
global.Log.Panic("请配置config")
|
||||
}
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx.UseAfterHandlerInterceptor(middleware.OperationHandler)
|
||||
// gin前置 函数
|
||||
ctx.UseBeforeHandlerInterceptor(ctx.PermissionHandler)
|
||||
// gin后置 函数
|
||||
ctx.UseAfterHandlerInterceptor(ctx.LogHandler)
|
||||
go func() {
|
||||
// 启动系统调度任务
|
||||
jobs.InitJob()
|
||||
jobs.Setup()
|
||||
}()
|
||||
starter.RunWebServer(initialize.InitRouter())
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.Flags().StringVar(&configFile, "config", getEnvStr("PANDA_CONFIG", "./config.yml"), "panda config file path.")
|
||||
}
|
||||
|
||||
func getEnvStr(env string, defaultValue string) string {
|
||||
v := os.Getenv(env)
|
||||
if v == "" {
|
||||
return defaultValue
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
rootCmd.PrintErrf("panda root cmd execute: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user