Skip to content

Commit

Permalink
Clean code and Readme updated
Browse files Browse the repository at this point in the history
  • Loading branch information
josepdcs committed Jan 17, 2025
1 parent 29ce541 commit 25f20f3
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/infrastructure/db/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
4 changes: 2 additions & 2 deletions internal/infrastructure/server/di/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/server/di/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/server/di/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 25f20f3

Please sign in to comment.