12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package application
- import (
- "baize-playground/server/application/service"
- "baize-playground/server/config"
- "git.sxidc.com/go-framework/baize"
- "git.sxidc.com/go-framework/baize/framework/core/api"
- "git.sxidc.com/go-framework/baize/framework/core/application"
- "net/http"
- )
- var appInstance *application.App
- func NewApp() {
- if appInstance != nil {
- return
- }
- appInstance = baize.NewApplication(config.GetConfig().ApplicationConfig)
- // 注册Router
- appInstance.Api().PrefixRouter().RegisterVersionedRouter("v1")
- }
- func DestroyApp() {
- if appInstance == nil {
- return
- }
- baize.DestroyApplication(appInstance)
- appInstance = nil
- }
- func Start() error {
- // 初始化服务
- for _, svc := range service.RegisteredServices {
- err := svc.Init(appInstance)
- if err != nil {
- return err
- }
- }
- err := appInstance.Start()
- if err != nil {
- return err
- }
- return nil
- }
- func Finish() error {
- err := appInstance.Finish()
- if err != nil {
- return err
- }
- // 销毁服务
- for _, svc := range service.RegisteredServices {
- err := svc.Destroy()
- if err != nil {
- return err
- }
- }
- return nil
- }
- func ServerHttpForTest(w http.ResponseWriter, req *http.Request) {
- appInstance.Api().RootRouter().(*api.RootRouter).ServerHttp(w, req)
- }
|