Skip to content

A user authentication, signin and verification backend template for golang websites.

Notifications You must be signed in to change notification settings

palSagnik/hermes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hermes

Go Authentication Service Template 🔐

A production-ready authentication service template built with Go, featuring user registration, login, and session management. This template uses Docker for containerization and follows modern security practices.

Features ✨

  • User registration and login
  • JWT-based authentication
  • Password hashing with bcrypt
  • Email verification
  • Docker containerization
  • RESTful API endpoints
  • Rate limiting by IP
  • Input validation

Tech Stack 🛠

  • Go 1.21+
  • PostgreSQL
  • Docker & Docker Compose
  • JWT for token management
  • Go-Fiber Web Framework

Prerequisites 📋

  • Docker and Docker Compose installed
  • Go 1.21 or higher (for local development)
  • Make (optional, for using Makefile commands)

Quick Start 🚀

  1. Clone the repository:
git clone /~https://github.com/palSagnik/hermes
cd go-auth-template
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your configurations
  1. Start the services using Docker Compose:
docker-compose up -d

The service will be available at http://localhost:9000

API Endpoints 🌐

Authentication

POST /auth/signup
POST /auth/login
GET  /auth/verify/{token}

Health Check

GET  /alive

User Management

GET    /api/users
GET    /api/userdetails

Environment Variables 🔧

export POSTGRES_USER="postgres"
export POSTGRES_PASSWORD="password"

export POSTGRES_HOST="postgres-db"
export POSTGRES_DATABASE="hermes"
export POSTGRES_SSLMODE="disable"

export APP_PORT="9000"

export PUBLIC_URL="localhost:9000"
export EMAIL_ID="s4ych33se.ctf@gmail.com"
export EMAIL_AUTH="API TOKEN"
export TOKEN_SECRET="SECRET"

Directory Structure 📁

hermes/
├── Dockerfile
├── README.md
├── backend
│   ├── config
│   │   ├── db.go
│   │   ├── general.go
│   │   └── mailsecrets.go
│   ├── database
│   │   ├── database.go
│   │   ├── pgdata
│   │   │   └── global
│   │   ├── queries.go
│   │   └── schemas.go
│   ├── go.mod
│   ├── go.sum
│   ├── handler
│   │   ├── api.go
│   │   ├── auth.go
│   │   └── misc.go
│   ├── main.go
│   ├── middleware
│   │   ├── middleware.go
│   │   └── ratelimiter.go
│   ├── models
│   │   └── authModels.go
│   ├── router
│   │   └── routes.go
│   ├── template
│   │   └── mail.html
│   └── utils
│       ├── mail.go
│       └── utils.go
├── compose.yml
└── scripts
    ├── init.sh
    ├── reset.sh
    └── run.sh

Development 💻

Running Locally

# Install dependencies
go mod download

# Run the server
# Uncomment POSTGRES_HOST = localhost
./scripts/run.sh

Docker Commands 🐳

# Run with Docker Compose
docker compose up -d

# View logs
docker compose logs -f

Security Considerations 🔒

  • Passwords are hashed using bcrypt
  • JWT tokens for authentication
  • Rate limiting on authentication endpoints
  • Input validation and sanitization

Contributing 🤝

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License 📝

This project is licensed under the MIT License - see the LICENSE file for details.

About

A user authentication, signin and verification backend template for golang websites.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published