1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package application
- import (
- "baize-demo/project/mono/application/service"
- "baize-demo/project/mono/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").
- AddMiddlewares(service.AuthMiddleware(appInstance.Infrastructure()))
- }
- 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)
- }
|