wizeline / ca-microservices-go Goto Github PK
View Code? Open in Web Editor NEWThis project is a template generator based on Golang focused on a Rest-API.
This project is a template generator based on Golang focused on a Rest-API.
Design a Topic strategy
The go modules suggest putting the packages at the top/root level as much as possible.
Advantages:
Implement JWT Authenticator
Implement Http Server
Implement the following controllers based on the Echo framework
Additionally, implement unit testing
Implement some of the most used DBMS on the market. The following are some of the proposals in higher priority order:
Implement Configuration using environment variables.
Add the most used loggers on the market
Implement Github Actions CI/CD
In the initial version, we only got a basic and functional version of the repository, so it is necessary to refine all its components.
To be refined:
Generate all mock objects required for the application.
dependabot
is currently throwing issues regarding dependency updates in the Actions
tab.
Jobs:
Implement the most used frameworks on the market
Wondering if it might be useful to retrieve the configuration by json or yaml files.
Create the test job in the CI workflow with PostgreSQL service support.
The following additional tasks must be addressed:
Cover all targets and improve(as needed) the documentation for the make help
statement
Implement the Service component on the following layers:
Also, please make sure to cover 100% of the testing.
Add PostgreSQL database driver.
Changes:
Optional: add PgAdmin support(PostgreSQL Web-GUI)
Migrate the deployment environment to Alpine-based images. The following infrastructure components must be migrated:
Add the "deployment" folder
Implement Swagger
Implement the Repository component on the following layers:
Also, please make sure to cover 100% of the testing.
In the initial version, we only got a basic and functional version of the controller, so it is necessary to refine all its components.
To be refined:
In the initial version, we only got a basic and functional version of the service, so it is necessary to refine all its components.
To be refined:
Issues to be fixed:
Add ZeroLog support
Improve Documentation about the following process and components.
make help
target/statementThis issue is to discuss the best project structure following a hexagonal architecture.
.
├── core (src) /
│ ├── movies/
│ │ ├── infraestructure/
│ │ │ ├── postgresql_movie_repository.go
│ │ │ ├── http_handlers.go
│ │ │ └── tests/
│ │ │ └── (unit test here)
│ │ ├── use_cases(services/application)/
│ │ │ ├── add_movie.go
│ │ │ ├── remove_movie.go
│ │ │ ├── requests */
│ │ │ │ └── add_movie_request.go
│ │ │ └── tests/
│ │ │ └── (unit test here)
│ │ └── domain/
│ │ ├── movie.go
│ │ ├── movies_repository.go (interface for repositories)
│ │ └── tests/
│ │ └── (integration tests here)
│ └── users/
│ ├── infraestructure/
│ │ ├── postgresql_user_repository.go
│ │ ├── http_handlers.go
│ │ └── tests
│ ├── use_cases(services/application)/
│ │ ├── add_user.go
│ │ ├── remove_user.go
│ │ ├── search_user.go
│ │ ├── requests */
│ │ │ └── add_user_request.go
│ │ └── tests
│ └── domain/
│ ├── user.go
│ └── user_repository.go (interface for repositories)
├── rest_api/
│ └── routes.go (we setup the routes here)
├── main.go
├── dockerfile
└── Makefile
Here the directories requests and responses in “usecases” are optional, they are suggested because we could define the DTOs (data transfer objects) we need them when an entity of a use case needs a complex input that isn’t defined a domain entity:
For example, you can find users with this necessity, source reddit
Yeah that is exactly what I was doing, until I faced this situation where I have a complex query that doesn't return any domain model, because the query involves lots of join between tables, so the object it is returning doesn't represent a unique domain model but multiple ones. So I need the data layer to return a complex object that doesn't represent pure DB entity, that's why I need a DTO.
An example of the use of DTOs can be found at this repo so a request would look like this in go:
package dto
import (
"github.com/ashishjuyal/banking-lib/errs"
"strings"
)
type NewAccountRequest struct {
CustomerId string `json:"customer_id"`
AccountType string `json:"account_type"`
Amount float64 `json:"amount"`
}
func (r NewAccountRequest) Validate() *errs.AppError {
if r.Amount < 5000 {
return errs.NewValidationError("To open a new account you need to deposit atleast 5000.00")
}
if strings.ToLower(r.AccountType) != "saving" && strings.ToLower(r.AccountType) != "checking" {
return errs.NewValidationError("Account type should be checking or saving")
}
return nil
}
We could also have a response directory to define the output of the use cases in case that they could be complex structs different from the domains. Also they could be defined in the same file as the use case.
package dto
type NewAccountResponse struct {
AccountId string `json:"account_id"`
}
A video of this structure can be found at this youtube video
This could be another approach, with this structure the first obvious thing is that we have a project that follows the hexagonal architecture, ins’t my favorite given the obscurity of some folder names (you’ll need to explain the complete architecture in the README for team members that don’t have the complete context).
.
├── .env
├── go.mod
├── go.sum
├── internal/
│ ├── core/
│ │ ├── domain/
│ │ │ ├── movies.go
│ │ │ └── users.go
│ │ ├── ports/
│ │ │ ├── movies_repository.go
│ │ │ └── users_repository.go
│ │ └── services/
│ │ ├── movies.go
│ │ └── users.go
│ └── adapters/
│ ├── http_handlers/
│ │ ├── movies_handler.go
│ │ └── users_handler.go
│ ├── repository/
│ │ └── postgres/
│ │ ├── users_repository.go
│ │ └── movies_repository.go
│ └── tests
└── rest_api/
└── main.go
We could also apply the use of DTOs for validation creating requests and responses folder or just define them in the file for each service.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.