This commit is contained in:
aozhiwei 2023-09-29 18:01:54 +08:00
parent 206070d18e
commit b46f1d1902
6 changed files with 88 additions and 14 deletions

View File

@ -1,35 +1,34 @@
package main package app
import ( import (
"f5" "f5"
"main/db"
"mt" "mt"
"main/constant"
) )
type App struct { type app struct {
} }
func (this *App) GetPkgName() string { func (this *app) GetPkgName() string {
return "adminserver" return "adminserver"
} }
func (this *App) Init() { func (this *app) Init() {
f5.LoadMetaTable(mt.Table) f5.LoadMetaTable(mt.Table)
this.registerDataSources() this.registerDataSources()
db.InitDB() //ginMgr.init()
ginMgr.init()
} }
func (this *App) UnInit() { func (this *app) UnInit() {
ginMgr.unInit() //ginMgr.unInit()
} }
func (this *App) Update() { func (this *app) Update() {
} }
func (this *App) registerDataSources() { func (this *app) registerDataSources() {
f5.GetJsStyleDb().RegisterDataSource( f5.GetJsStyleDb().RegisterDataSource(
GAME_DB, constant.GAME_DB,
mt.Table.GameDb.GetById(0).GetHost(), mt.Table.GameDb.GetById(0).GetHost(),
mt.Table.GameDb.GetById(0).GetPort(), mt.Table.GameDb.GetById(0).GetPort(),
mt.Table.GameDb.GetById(0).GetUser(), mt.Table.GameDb.GetById(0).GetUser(),
@ -37,7 +36,7 @@ func (this *App) registerDataSources() {
mt.Table.GameDb.GetById(0).GetDatabase(), mt.Table.GameDb.GetById(0).GetDatabase(),
30) 30)
f5.GetJsStyleDb().RegisterDataSource( f5.GetJsStyleDb().RegisterDataSource(
FRIEND_DB, constant.FRIEND_DB,
mt.Table.FriendDb.GetById(0).GetHost(), mt.Table.FriendDb.GetById(0).GetHost(),
mt.Table.FriendDb.GetById(0).GetPort(), mt.Table.FriendDb.GetById(0).GetPort(),
mt.Table.FriendDb.GetById(0).GetUser(), mt.Table.FriendDb.GetById(0).GetUser(),

View File

@ -0,0 +1,12 @@
package app
import (
"main/constant"
"main/global"
)
var _app = new(app)
func init() {
global.RegModule(constant.APP_MODULE_IDX, _app)
}

View File

@ -0,0 +1,5 @@
package common
type App interface {
Run(func(), func())
}

View File

@ -8,3 +8,8 @@ const (
GAME_DB = "gamedb" GAME_DB = "gamedb"
FRIEND_DB = "firenddb" FRIEND_DB = "firenddb"
) )
const (
APP_MODULE_IDX = iota
MAX_MODULE_IDX
)

View File

@ -0,0 +1,47 @@
package global
import (
"q5"
"fmt"
"main/constant"
"main/common"
)
var modules [constant.MAX_MODULE_IDX]q5.Module
var initOrders = []int32 {
}
var app common.App
func GetApp() common.App {
return app
}
func RegModule(idx int32, m q5.Module) {
fmt.Printf("RegModule module %d\n", idx)
modules[idx] = m
switch (idx) {
case constant.APP_MODULE_IDX:
{
app = m.(common.App)
}
default:
{
panic("unknow module")
}
}
}
func InitModules() {
for _, val := range(initOrders) {
fmt.Printf("init module %d\n", val)
modules[val].Init()
}
}
func UnInitModules() {
for _, val := range(initOrders) {
fmt.Printf("unInit module %d", val)
modules[val].UnInit()
}
}

View File

@ -1,5 +1,11 @@
package initialize package initialize
func Init() { import (
_ "main/app"
. "main/global"
)
func Init() {
GetApp().Run(InitModules, UnInitModules)
} }