infrastructure.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package infrastructure
  2. import (
  3. "git.sxidc.com/go-framework/baize/infrastructure/database/data_service"
  4. "git.sxidc.com/go-framework/baize/infrastructure/database/operations"
  5. )
  6. type Config struct {
  7. DatabaseConfig
  8. }
  9. type DatabaseConfig struct {
  10. Operations *operations.Config
  11. }
  12. type Infrastructure struct {
  13. dbOperations *operations.Operations
  14. dataService *data_service.DataService
  15. }
  16. func NewInfrastructure(config Config) *Infrastructure {
  17. i := new(Infrastructure)
  18. if config.DatabaseConfig.Operations != nil {
  19. op, err := operations.NewOperations(config.DatabaseConfig.Operations)
  20. if err != nil {
  21. panic("创建数据库操作失败" + err.Error())
  22. }
  23. i.dbOperations = op
  24. }
  25. return i
  26. }
  27. func DestroyInfrastructure(i *Infrastructure) {
  28. if i == nil {
  29. return
  30. }
  31. if i.dbOperations != nil {
  32. err := operations.DestroyOperation(i.dbOperations)
  33. if err != nil {
  34. panic("销毁数据库操作失败" + err.Error())
  35. }
  36. }
  37. return
  38. }
  39. func (i Infrastructure) GetDBOperations() *operations.Operations {
  40. return i.dbOperations
  41. }
  42. func (i Infrastructure) GetDataService() *data_service.DataService {
  43. return i.dataService
  44. }