/git-badges-golang

Show your GitHub stats with Shields.io badges

Primary LanguageGoMIT LicenseMIT

git-badges-golang

git-badges-golang

Show your GitHub stats in badges

Inspired by git-badges and serverless-github-badges but implemented in Golang

Features

Visits

Visits Badge

Number of visitors the user had, recorded in a MongoDB database and updated on every GET request

Endpoint

https://badges.temir.dev/visits?username={username}&repo={repo}&style=for-the-badge&logo=github&color=yellow

Markdown

[![Visits Badge](https://badges.temir.dev/visits?username={username}&repo={repo}&style=for-the-badge&logo=github&color=yellow)](https://badges.temir.dev/visits?username={username}&repo={repo}&style=for-the-badge&logo=github&color=yellow)

Organizations

Organizations Badge

Number of organizations the user is a part of

Endpoint

https://badges.temir.dev/organizations?username={username}&style=for-the-badge&logo=github&color=yellow

Markdown

[![Organizations Badge](https://badges.temir.dev/organizations?username={username}&style=for-the-badge&logo=github&color=yellow)](https://badges.temir.dev/organizations?username=dtemir&style=for-the-badge&logo=github&color=yellow)

Reference

GitHub's API


Years

Years Badge

Number of years the user has been registered at GitHub

Endpoint

https://badges.temir.dev/years?username={username}&style=for-the-badge&logo=github&color=yellow

Markdown

[![Years Badge](https://badges.temir.dev/years?username={username}&style=for-the-badge&logo=github&color=yellow)](https://badges.temir.dev/years?username=dtemir&style=for-the-badge&logo=github&color=yellow)

Reference

GitHub's API


Repos

Repos Badge

Number of public repositories the user owns

Endpoint

https://badges.temir.dev/repos?username={username}&style=for-the-badge&logo=github&color=yellow

Markdown

[![Repos Badge](https://badges.temir.dev/repos?username={username}&style=for-the-badge&logo=github&color=yellow)](https://badges.temir.dev/repos?username=dtemir&style=for-the-badge&logo=github&color=yellow)

Reference

GitHub's API


Deploy

If you would like to deploy it yourself, please follow these steps:

Manually

  1. Install Go
  2. Install MongoDB Community
  3. Download dependencies with go mod download
  4. Create a .env file with a GitHub token (look at .env.example)
  5. Run with go run *.go

Docker (Recommended)

  1. Install Docker Engine with the Compose plugin
  2. Create a .env file with a GitHub token (look at .env.example)
  3. Build an image with docker compose up (add -d if you want to run it in the background)

Don't forget to run tests go test to make sure everything works correctly!

Reverse Proxy and SSL/TLS

  • To avoid having to send all requests to port 8080, you want to setup a reverse proxy that will forward traffic through port 80 (the default port when accessing websites)
    • If this wasn't setup, you would have to access the website through badges.temir.dev:8080 instead of regular badges.temir.dev
  • To avoid using HTTP and use secure HTTPS instead, you want to receive an SSL certificate with Let's Encrypt, which is automatable with certbot
    • If this wasn't setup, you would have to make requests to http://badges.temir.dev instead of https://badges.temir.dev and it would cause problems with common browsers

Find how to accomplish both of these things in this article: here

CI/CD

To make sure this project is properly maintained, I used GitHub workflows to test and automatically deploy to Oracle Cloud Micro Instance that comes with Always Free Tier

You can find workflows under Actions

  1. check_build.yml to make sure Go compiles
  2. check_compose.yml to make sure docker-compose.yml is up-to-date
  3. deploy.yml to deploy the latest changes to Oracle Cloud