| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package infrastructure
- import (
- "git.sxidc.com/go-framework/baize/infrastructure/database/data_service"
- "git.sxidc.com/go-framework/baize/infrastructure/database/operations"
- )
- type Config struct {
- DatabaseConfig
- }
- type DatabaseConfig struct {
- Operations *operations.Config
- DataService *data_service.Config
- }
- type Infrastructure struct {
- dbOperations *operations.Operations
- dataService *data_service.DataService
- }
- func NewInfrastructure(config Config) *Infrastructure {
- i := new(Infrastructure)
- if config.DatabaseConfig.Operations != nil {
- op, err := operations.NewOperations(config.DatabaseConfig.Operations)
- if err != nil {
- panic("创建数据库操作失败" + err.Error())
- }
- i.dbOperations = op
- }
- if config.DatabaseConfig.DataService != nil {
- dataService, err := data_service.NewDataService(config.DatabaseConfig.DataService)
- if err != nil {
- panic("创建数据服务失败" + err.Error())
- }
- i.dataService = dataService
- }
- return i
- }
- func DestroyInfrastructure(i *Infrastructure) {
- if i == nil {
- return
- }
- if i.dataService != nil {
- err := data_service.DestroyDataService(i.dataService)
- if err != nil {
- panic("销毁数据服务失败" + err.Error())
- }
- }
- if i.dbOperations != nil {
- err := operations.DestroyOperation(i.dbOperations)
- if err != nil {
- panic("销毁数据库操作失败" + err.Error())
- }
- }
- return
- }
- func (i Infrastructure) DBOperations() *operations.Operations {
- return i.dbOperations
- }
- func (i Infrastructure) DataService() *data_service.DataService {
- return i.dataService
- }
|