baize.go 972 B

1234567891011121314151617181920212223242526272829303132
  1. package baize
  2. import (
  3. "git.sxidc.com/go-framework/baize/framework/core/api"
  4. "git.sxidc.com/go-framework/baize/framework/core/application"
  5. "git.sxidc.com/go-framework/baize/framework/core/infrastructure"
  6. )
  7. func NewApplication(conf application.Config) *application.App {
  8. // 创建API
  9. apiConfig := conf.ApiConfig
  10. apiInstance := api.New(api.WithUrlPrefix(apiConfig.UrlPrefix),
  11. api.WithPort(apiConfig.Port),
  12. api.WithLogSkipPaths(apiConfig.LogSkipPaths...))
  13. // 创建基础设施
  14. infrastructureConfig := new(infrastructure.Config)
  15. infrastructureConfig.DatabaseConfig = conf.InfrastructureConfig.Database
  16. infrastructureConfig.CacheConfig = conf.InfrastructureConfig.Cache
  17. infrastructureInstance := infrastructure.NewInfrastructure(*infrastructureConfig)
  18. return application.New(apiInstance, infrastructureInstance)
  19. }
  20. func DestroyApplication(app *application.App) {
  21. if app == nil {
  22. return
  23. }
  24. infrastructure.DestroyInfrastructure(app.Infrastructure())
  25. }