DEV Community

loading...
Cover image for Go Clean architecture rest api example 🚀👋👨‍💻

Go Clean architecture rest api example 🚀👋👨‍💻

aleksk1ng profile image Alexander ・2 min read

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 👨‍💻 :)

Discussion (1)

pic
Editor guide
Collapse
s0xzwasd profile image
Daniil Maslov

Thanks Alexander!