From cb0847c3f571313a4d76da98fc10b0340bcf49ad Mon Sep 17 00:00:00 2001 From: yangduo Date: Wed, 21 Aug 2024 14:36:01 +0800 Subject: [PATCH] gameswitch list --- server/marketserver/api/v1/enter.go | 2 + .../marketserver/api/v1/game_switch/enter.go | 5 +++ .../api/v1/game_switch/gswitch.go | 41 +++++++++++++++++++ server/marketserver/app/app.go | 11 +++++ server/marketserver/constant/constant.go | 1 + .../marketserver/router/game_switch/enter.go | 5 +++ .../router/game_switch/game_switch.go | 13 ++++++ server/marketserver/router/routermgr.go | 3 ++ 8 files changed, 81 insertions(+) create mode 100644 server/marketserver/api/v1/game_switch/enter.go create mode 100644 server/marketserver/api/v1/game_switch/gswitch.go create mode 100644 server/marketserver/router/game_switch/enter.go create mode 100644 server/marketserver/router/game_switch/game_switch.go diff --git a/server/marketserver/api/v1/enter.go b/server/marketserver/api/v1/enter.go index 47db03d5..272c7207 100644 --- a/server/marketserver/api/v1/enter.go +++ b/server/marketserver/api/v1/enter.go @@ -4,6 +4,7 @@ import ( "main/api/v1/activity" "main/api/v1/asset" "main/api/v1/event" + "main/api/v1/game_switch" "main/api/v1/gold_bullion" "main/api/v1/hero" "main/api/v1/ingame" @@ -26,6 +27,7 @@ type ApiGroup struct { ActivityApiGroup activity.ApiGroup EventApiGroup event.ApiGroup RechargeApiGroup recharge.ApiGroup + SwitchApiGroup game_switch.ApiGroup } var ApiGroupApp = new(ApiGroup) diff --git a/server/marketserver/api/v1/game_switch/enter.go b/server/marketserver/api/v1/game_switch/enter.go new file mode 100644 index 00000000..0cac7f13 --- /dev/null +++ b/server/marketserver/api/v1/game_switch/enter.go @@ -0,0 +1,5 @@ +package game_switch + +type ApiGroup struct { + GameSwitchApi +} diff --git a/server/marketserver/api/v1/game_switch/gswitch.go b/server/marketserver/api/v1/game_switch/gswitch.go new file mode 100644 index 00000000..6f75be2e --- /dev/null +++ b/server/marketserver/api/v1/game_switch/gswitch.go @@ -0,0 +1,41 @@ +package game_switch + +import ( + "f5" + "main/constant" + "net/http" + "q5" + + "github.com/gin-gonic/gin" +) + +type GameSwitchApi struct { +} + +func (this *GameSwitchApi) List(c *gin.Context) { + f5.GetGoStyleDb().RawQuery( + constant.CONF_DB, + "SELECT * FROM t_game_switch WHERE 1=1", + []string{}, + func(err error, ds *f5.DataSet) { + if err != nil { + c.JSON(http.StatusOK, gin.H{ + "code": 1, + "message": err.Error(), + }) + return + } + + data := map[string]int32{} + for ds.Next() { + data[ds.GetByName("switch_name")] = q5.SafeToInt32(ds.GetByName("is_open")) + } + + c.JSON(http.StatusOK, gin.H{ + "code": 0, + "message": "获取成功", + "contributionPoint": "", + "data": data, + }) + }) +} diff --git a/server/marketserver/app/app.go b/server/marketserver/app/app.go index 575be92d..70152d4d 100644 --- a/server/marketserver/app/app.go +++ b/server/marketserver/app/app.go @@ -97,6 +97,17 @@ func (this *app) registerDataSources() { 1, mt.Table.AccountDb.GetById(0).GetMaxOpenConns(), mt.Table.AccountDb.GetById(0).GetMaxIdleConns()) + + f5.GetGoStyleDb().RegisterDataSource( + constant.CONF_DB, + mt.Table.ConfDb.GetById(0).GetHost(), + mt.Table.ConfDb.GetById(0).GetPort(), + mt.Table.ConfDb.GetById(0).GetUser(), + mt.Table.ConfDb.GetById(0).GetPasswd(), + mt.Table.ConfDb.GetById(0).GetDatabase(), + 1, + mt.Table.ConfDb.GetById(0).GetMaxOpenConns(), + mt.Table.ConfDb.GetById(0).GetMaxIdleConns()) } func (this *app) HasTask() bool { diff --git a/server/marketserver/constant/constant.go b/server/marketserver/constant/constant.go index 13006a48..ba291c13 100644 --- a/server/marketserver/constant/constant.go +++ b/server/marketserver/constant/constant.go @@ -5,6 +5,7 @@ const ( BCNFT_DB = "bcnftdb" BCEVENT_DB = "bceventdb" GAME_DB = "gamedb" + CONF_DB = "confdb" ) const ( diff --git a/server/marketserver/router/game_switch/enter.go b/server/marketserver/router/game_switch/enter.go new file mode 100644 index 00000000..1871e5c2 --- /dev/null +++ b/server/marketserver/router/game_switch/enter.go @@ -0,0 +1,5 @@ +package game_switch + +type RouterGroup struct { + GameSwitchRouter +} diff --git a/server/marketserver/router/game_switch/game_switch.go b/server/marketserver/router/game_switch/game_switch.go new file mode 100644 index 00000000..9811f62c --- /dev/null +++ b/server/marketserver/router/game_switch/game_switch.go @@ -0,0 +1,13 @@ +package game_switch + +import ( + "f5" + v1 "main/api/v1" +) + +type GameSwitchRouter struct{} + +func (this *GameSwitchRouter) InitRouter() { + api := v1.ApiGroupApp.SwitchApiGroup + f5.GetApp().GetGinEngine().GET("/api/server_switch", api.GameSwitchApi.List) +} diff --git a/server/marketserver/router/routermgr.go b/server/marketserver/router/routermgr.go index f5a45371..61ee28cb 100644 --- a/server/marketserver/router/routermgr.go +++ b/server/marketserver/router/routermgr.go @@ -6,6 +6,7 @@ import ( "main/router/activity" "main/router/asset" "main/router/event" + "main/router/game_switch" "main/router/gold_bullion" "main/router/hero" "main/router/ingame" @@ -28,6 +29,7 @@ type routerMgr struct { activity activity.RouterGroup event event.RouterGroup recharge recharge.RouterGroup + gameswitch game_switch.RouterGroup } func (this *routerMgr) Init() { @@ -45,6 +47,7 @@ func (this *routerMgr) Init() { this.activity.ContributionRouter.InitRouter() this.event.EventRouter.InitRouter() this.recharge.RechargeRouter.InitRouter() + this.gameswitch.GameSwitchRouter.InitRouter() f5.GetSysLog().Info("routerMgr.init")