DEV Community

Cover image for Go Clean architecture rest api example πŸš€πŸ‘‹πŸ‘¨β€πŸ’»
Alexander
Alexander

Posted on

Go Clean architecture rest api example πŸš€πŸ‘‹πŸ‘¨β€πŸ’»

I write my first Go simple example project, it doesn't has any advanced business logic or full test coverage, but i hope it can be intresting and usefull for someone πŸ€“. I didn't write all in details with code examples, here is link on Github repository, but if my pet project would be interesting for someone, so ready to share all my existing experience on this moment :)

Tried to create Clean Architecture REST API closer to real world production projects using, PostgreSQL as database, Redis for sessions and caching,
AWS S3 for images uploading, Jaeger OpenTracing, Prometheus and Grafana metrics,
Swagger documentation, Docker infrastructure for development.
For web framework i have chosen most popular for today Echo, another possible good alternatives Gin, Chi, Mux.
SQL db standard solution on my opinion is combination of sqlx and pgx.
Redis for sessions and caching go-redis
Viper for configuration.
Zap for logger, but this two is good too zerolog and logrus.
Swagger for api documentation, i used swag, another good one is go-swagger
MinIO for AWS S3 good variant minio-go
Validator is good solution for validation.
For testing and mocking testify and gomock very good tools.
Session and Token Based Authentication, implemented both for this example project, used jwt-go for JWT.
For database migrations i found migrate is very nice tool and recommend use it.

Wraped all in docker, but for local development i found more cofortable separate run docker-compose with all necessary containers and separate run Go application, because its easier and faster for debug and rebuild.
For docker development created compose file with hot reloading using CompileDaemon.

Full list of used technologies and source code u can find here πŸ‘¨β€πŸ’» :)

Top comments (2)

Collapse
 
s0xzwasd profile image
Daniil Maslov

Thanks Alexander!

Collapse
 
lexuanquynh profile image
Jupiter • Edited

I found your repository by google search. Do you have the articles for this repository? thanks for your sharing.