Pet project about how to connect to mongodb, work with gRPC and HTTP/REST. Code structure follows clean code (not fully, I guess :D).
- clone
.env.example
and change its name to.env
- create mongodb database with
event
collection - This project uses
go dep
to manage dependencies. So after installgo dep
rundep ensure
. - RUN
go run cmd/main.go
orgo build cmd/main.go && ./main
- Use whatever you like to test RESTful API (I personally like using insomnia). For event api I create 2 endpoints:
curl -X GET 'http://localhost:8080/v1/event'
(for event list)curl -X POST 'http://localhost:8080/v1/event' -d '{"body": "test 3ewjrhewjfk"}'
(for create)
this folder contains our gRPC proto files. I use v1 folder for versioning api. Each *.proto
file represents APIs relevant to an entity inside storage
folder. After create an proto
file run ./protoc-gen.sh {version} {entity}
(ex: ./protoc-gen.sh v1 event
) to generate others files.
this is where our entities live. Each file declares entity struct and methods to interact with it.
If you familiar with repository-service pattern, this is where we write business logic.
handler is api endpoints
main package, it calls run server gRPC and HTTP/REST