SQL database. Postgres 12 in this case. Potentially can be replaced with more recent version. Runs inside Docker
sqlc to interact with Postgres. And the lib/pq as the driver. Can be replaced with pgx later. SQLC docs
golang-migrate to facilitate DB migrations. Currently as a standalone CLI. Can be moved to the container version.
viper to load configs.
dotenv to load the API_KEY for the 3rd party service.
testify to run asserts, mocks etc.
uuid from Google to generate random unique string that we use as a token
gin-gonic as a web-framework to serve our API
net/http standard package to query external API
protoc compiler to work with protobufs (not finished yet)
Makefile to make some aliasing simpler.
Workflow Instructions
Check the app.env file. It contains the config of our app.
This information is sensitive and commited to the repo just for the development purposes. Viper will read this file and populate some configs.
Put your Weather API key into .env file in the root of the repository. Precede it with WEATHER_API_KEY=
Run the next set of commands to check the work
make postgres to create the postgres container in the docker network. (TBD use Docker Compose to spin up the DB)
make migrateup to run the migrations.
make sqlc to generate sqlc idiomatic Go code to interact with Postgresql
make test to run DB tests (only weather-api/db/sqlc is covered at this time)
make server to run the server
Postman can be used if necessary. But curl is used for the simplicity sake.
Test Subscribe Endpoint: Open the new terminal window and run curl -X POST -H "Content-Type: application/json" -d @req1.json http://localhost:8080/api/subscribe | jq
Connect to the db via DBeaver or alike tool to check the result. There are some remnants of testing with garbage data. It could be cleaned up later.
Test Confirm Endpoint: Open the new terminal window and run curl -X GET http://localhost:8080/api/confirm/2d77cd87-161f-4efb-a9f0-8831aa52cd44
Test Weather Endpoint: Open the new terminal window and run curl -X GET http://localhost:8080/api/weather?city=Kyiv
Test UnSubscribe Endpoint: Open the new terminal window and run curl -X GET http://localhost:8080/api/unsubscribe/3d64fede-e088-4b15-9b4c-94cf1 where the last part is the token which can be copied from the DB column.
Use make proto to build the pb.go files from proto into the pb directory (UNDER CONSTRUCTION)