| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package ops
- import (
- "embed"
- cherryApp "f1-game/internal/cherry_app"
- funcLoad "f1-game/internal/component/func_load"
- cgops "f1-game/internal/component/gops"
- "f1-game/internal/component/rate"
- "f1-game/internal/data"
- "f1-game/nodes/ops/controller"
- "io/fs"
- "net/http"
- "github.com/cherry-game/cherry"
- csnowflake "github.com/cherry-game/cherry/extend/snowflake"
- cfacade "github.com/cherry-game/cherry/facade"
- cgin "github.com/cherry-game/components/gin"
- )
- func Run(node cfacade.INode) {
- app := cherry.ConfigureNode(
- node,
- false,
- cherry.Cluster,
- )
- app.Register(initFunc())
- app.Register(cgops.New())
- app.Register(data.New())
- app.Register(newOpsServer(app))
- app.Startup()
- }
- func initFunc() cfacade.IComponent {
- fn := func(app cfacade.IApplication) {
- csnowflake.InitDefaultNode(app.NodeID())
- cherryApp.Init(app)
- }
- return funcLoad.New("initFunc", fn)
- }
- //go:embed static/*
- var staticFS embed.FS
- func newOpsServer(app *cherry.AppBuilder) *cgin.Component {
- opsServer := cgin.NewHttp("ops_http_server", app.Address())
- opsServer.Use(cgin.Cors())
- opsServer.Use(cgin.RecoveryWithZap(true))
- opsServer.Use(rate.GinRateWithIP())
- opsServer.Register(controller.List()...)
- // 静态文件服务
- // opsServer.Static("/static", "./static")
- subFS, err := fs.Sub(staticFS, "static")
- if err != nil {
- panic(err)
- }
- opsServer.StaticFS("/static", http.FS(subFS))
- return opsServer
- }
|