diff --git a/README.md b/README.md index 8af4c95..efa4dcc 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,8 @@ In this project, I have aimed to adhere to Golang naming conventions and best pr - [GORM](https://gorm.io/index.html) with [PostgresSQL](https://gorm.io/docs/connecting_to_the_database.html#PostgreSQL)The fantastic ORM library for Golang aims to be developer friendly. - [Wire](https://github.com/google/wire) is a code generation tool that automates connecting components using dependency injection. - [Koanf](https://github.com/knadh/koanf) is a library for reading configuration from different sources in different formats in Go applications. It is a cleaner, lighter [alternative to spf13/viper](https://github.com/knadh/koanf#alternative-to-viper) with better abstractions and extensibility and far fewer dependencies.. -- [swag](https://github.com/swaggo/swag) converts Go annotations to Swagger Documentation 2.0 with [fiber-swagger](https://github.com/gofiber/swagger) and [swaggo files](github.com/swaggo/files) +- [Swag](https://github.com/swaggo/swag) converts Go annotations to Swagger Documentation 2.0 with [fiber-swagger](https://github.com/gofiber/swagger) and [swaggo files](github.com/swaggo/files) +- [Testify](https://github.com/stretchr/testify) is a set of packages that provide many tools for testifying that your code will behave as you intend. Features include: easy assertions, mocking, testing suite interfaces and functions, and a test runner. ## Using `go-proposal-hexagonal-arch` project diff --git a/cmd/api/main.go b/cmd/api/main.go index bfdcde6..b4bf0b8 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -13,7 +13,7 @@ func main() { log.Fatal("cannot load c: ", err) } - server, err := di.InitializeAPI(cfg) + server, err := di.InitializeAPI(cfg.DB) if err != nil { log.Fatal("cannot start server: ", err) } else { diff --git a/internal/infrastructure/db/connection.go b/internal/infrastructure/db/connection.go index a9a2482..22b2321 100644 --- a/internal/infrastructure/db/connection.go +++ b/internal/infrastructure/db/connection.go @@ -9,8 +9,8 @@ import ( "gorm.io/gorm" ) -func ConnectDatabase(cfg config.Config) (*gorm.DB, error) { - psqlInfo := fmt.Sprintf("host=%s user=%s dbname=%s port=%s password=%s", cfg.DB.Host, cfg.DB.User, cfg.DB.Name, cfg.DB.Port, cfg.DB.Password) +func ConnectDatabase(cfg config.DB) (*gorm.DB, error) { + psqlInfo := fmt.Sprintf("host=%s user=%s dbname=%s port=%s password=%s", cfg.Host, cfg.User, cfg.Name, cfg.Port, cfg.Password) db, err := gorm.Open(postgres.Open(psqlInfo), &gorm.Config{ SkipDefaultTransaction: true, }) diff --git a/internal/infrastructure/server/di/factory.go b/internal/infrastructure/server/di/factory.go index 641cad6..7c04a70 100644 --- a/internal/infrastructure/server/di/factory.go +++ b/internal/infrastructure/server/di/factory.go @@ -8,8 +8,8 @@ import ( ) // ResolveUserRepository resolves the user repository based on the configuration -func ResolveUserRepository(cfg config.Config) (repository.User, error) { - if cfg.DB.Type != config.InMemoryDB { +func ResolveUserRepository(cfg config.DB) (repository.User, error) { + if cfg.Type != config.InMemoryDB { DB, err := db.ConnectDatabase(cfg) if err != nil { return nil, err diff --git a/internal/infrastructure/server/di/wire.go b/internal/infrastructure/server/di/wire.go index 00f54a9..63af8ff 100644 --- a/internal/infrastructure/server/di/wire.go +++ b/internal/infrastructure/server/di/wire.go @@ -11,7 +11,7 @@ import ( "github.com/josepdcs/go-proposal-hexagonal-arch/internal/infrastructure/server/http" ) -func InitializeAPI(cfg config.Config) (*http.Server, error) { +func InitializeAPI(cfg config.DB) (*http.Server, error) { wire.Build( ResolveUserRepository, usecase.NewUserFinderAll, diff --git a/internal/infrastructure/server/di/wire_gen.go b/internal/infrastructure/server/di/wire_gen.go index 1bb92a7..9b46a58 100644 --- a/internal/infrastructure/server/di/wire_gen.go +++ b/internal/infrastructure/server/di/wire_gen.go @@ -15,7 +15,7 @@ import ( // Injectors from wire.go: -func InitializeAPI(cfg config.Config) (*http.Server, error) { +func InitializeAPI(cfg config.DB) (*http.Server, error) { user, err := ResolveUserRepository(cfg) if err != nil { return nil, err