Socket
Book a DemoInstallSign in
Socket

github.com/kirildevops/weather-api

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/kirildevops/weather-api

Source
Go
Version
v0.0.0-20250518203404-37663e76c706
Version published
Created
Source

Overview

Solution Stack

  • Project structure have been influenced by following along with the course backend-master-class-golang-postgresql-kubernetes Some parts were replicated (NOT copied) from the course video.

  • 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)

FAQs

Package last updated on 18 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts