
Product
Announcing Bun and vlt Support in Socket
Bringing supply chain security to the next generation of JavaScript package managers
github.com/vinodhalaharvi/weather-api
Advanced tools
If you want to run the application directly
# sync dependencies
go generate ./...
go run main.go
Just use localhost:8080 with the routes below to access the application.
If you want to use docker-compose
docker-compose up --build
Add gin-app.local to your /etc/hosts file
Navigate to https://gin-app.local/ping. Other routes that are active for this application are shown below.
You will have to replace YOUR_OPEN_WEATHER_API_KEY with your own Open Weather API key. Please not the onecall V3.0 API
requires a paid subscription to Open Weather API.
This project leverages the power of the Gin server for backend operations, providing a robust and efficient handling of weather-related data queries. It's designed to be flexible, with deployment configurations for Containerized environment.
Dockerfile and docker-compose.yml for easy deployment, showcasing a sample setup
that can be run locally or in a containerized environment.localhost:8080 to access the Gin server, or deploy
using docker-compose.yml to include a full stack with Traefik reverse proxy, Prometheus, Grafana, Traefik dashboard,
and Alertmanager.To run this project locally:
go generate ./... ; go run main.go to start
the Gin server
on localhost:8080.docker-compose up to spin up the full stack, including the Traefik reverse proxy
setup and monitoring tools.For deploying to Kubernetes, convert the docker-compose.yml to Kubernetes manifests using tools like Kompose, and
apply them to your cluster.
Access the Traefik dashboard for an overview of the routing configurations and services, and use Prometheus and Grafana for monitoring metrics and setting up alerts through Alertmanager.
Explore the GraphQL interface at http://localhost:8080/query for interactive queries and to leverage the full
capabilities of the supported Weather API versions.
Deployment using docker-compose
Deploying the application with Docker Compose streamlines the setup process, ensuring all components—including the Gin server, Traefik reverse proxy, Prometheus, Grafana, and Alertmanager—are properly configured and interconnected. This guide walks you through the deployment process, focusing on HTTPS setup with self-signed certificates (test certs are already included if you just want to skip this step).
This project uses self-signed certificates to secure communications via HTTPS. For simplicity and ease of setup, we're including these certificates in the repository. If you're looking for a more robust solution for a production environment, integrating Let's Encrypt with Traefik for automatic certificate management is a recommended enhancement.
Using Included Certificates:
gin-app.local. There's no need to generate
new ones unless you want to customize your setup or refresh the certificates.Accessing the Application:
gin-app.local as the host, you'll need to ensure your system recognizes this hostname and
routes it to your local machine. The easiest way to achieve this is by adding an entry to your /etc/hosts file.127.0.0.1 gin-app.local
This step is crucial for accessing the website using the correct host, especially when using tools like curl that allow specifying hosts directly. For web browsers and most other use cases, editing the /etc/hosts file simplifies access.
The Traefik server is configured to automatically redirect HTTP traffic to HTTPS, leveraging the self-signed certificates. This ensures all communications are encrypted without requiring manual intervention.
To deploy and start the application using Docker Compose: Navigate to the root directory of the project where the docker-compose.yml file is located. Run the following command to build and start the services:
docker-compose up --build
This command builds the Go project and runs it inside Docker, alongside the other services defined in the docker-compose.yml.
After starting the services, you can access the application via https://gin-app.local/ping in your web browser or use curl with the --insecure flag to bypass SSL validation for testing:
curl --insecure https://gin-app.local/ping
Remember, since we're using self-signed certificates, web browsers will likely warn you about the site's security certificate. You can proceed past this warning in development environments.
If you want use your own certificates, you can generate them using the following command: (Optional)
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout gin-app.local.key -out gin-app.local.crt -subj "
/CN=gin-app.local"
Simple sequence diagram to show the flow of the application
sequenceDiagram
participant Client
participant Traefik
participant Gin
participant OpenWeatherAPI
Client ->> Traefik: Request (GraphQL or GET URL)
Traefik ->> Traefik: HTTP to HTTPS Redirection
Traefik ->> Traefik: Rate Limit Check
Traefik ->> Gin: Load Balances Request
Gin ->> OpenWeatherAPI: Forwards request to Open Weather API
alt Version V3.0
OpenWeatherAPI ->> Gin: Response from Open Weather API V3.0
else Version V2.5
OpenWeatherAPI ->> Gin: Response from Open Weather API V2.5
end
Gin ->> Gin: Assess Temperature (Cold Assessment)
Gin ->> Client: Response

FAQs
Unknown package
Did you know?

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.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.