Go Microservice framework is a command-line tool designed to rapidly generate microservice boilerplate code for Go backends. It scaffolds a production-ready project structure including routers, controllers, services, entities, Dockerfiles, and essential configuration files. The generated services follow best practices for modular and maintainable microservice development.
This tool supports generating RESTful microservices with plans to extend support for GraphQL and gRPC APIs.
- Generate boilerplate code for Go microservices with a clean architecture
- Auto-assign or specify network ports intelligently avoiding conflicts
- Create shared packages for entities, database connections, and HTTP middleware
- CLI-based interaction powered by Cobra
- Cross-platform support with pre-built binaries for Linux, macOS, and Windows
- Automated GitHub Actions workflow for seamless releases
gores aims to give you a head start by providing a well-structured and functional microservice skeleton:
Your generated service will adhere to common Go project layout recommendations:
cmd/main.go— The entry point for the microservice application.internal/— Contains internal packages for the service's specific logic (e.g.,router.go,controller.go,service.go). This structure promotes modularity and clean architecture.pkg/(Shared) — A core part of the monorepo, containing shared packages:entities/: Defines common data models likeUser(withEmail,Name,PasswordHash,CreatedAt,UpdatedAt) and other domain entities. TheUserentity is designed for secure password handling with bcrypt password hashes.database/postgres/: Provides a reusable function for connecting to a PostgreSQL database using GORM.http/middleware/: Houses global HTTP middleware (e.g., for JWT authentication, API key validation, CORS, logging).
- Services load configuration from
.envfiles usinggodotenv, allowing easy management of environment-specific settings (like database credentials, JWT secrets, ports).
- A robust GORM ORM integration for PostgreSQL database interactions.
- Database connection details (host, port, user, password, SSL mode) are read from environment variables.
- Includes database connection health checking on startup and graceful closing during shutdown.
- Automigrations: Services can be configured to automatically migrate database schemas based on your GORM models.
- Leverages the high-performance Fiber web framework for building HTTP APIs.
- Automatically sets up basic routing and integrates your shared HTTP middleware.
- Includes routes for basic operations (e.g., health checks, user upsert/login, user CRUD if applicable).
- The default
auth-serviceimplements production-ready bcrypt password hashing for storing user credentials securely. - Facilitates JWT (JSON Web Token) issuance upon user registration/login for application-specific authentication.
- Includes middleware for JWT and API Key based authentication, allowing you to protect your service endpoints with flexible access control (e.g., requiring EITHER a valid JWT OR an API Key for certain routes).
- All generated services are equipped with graceful shutdown logic, ensuring that HTTP servers and database connections are closed cleanly upon receiving
SIGINT(Ctrl+C) orSIGTERMsignals, preventing data corruption and resource leaks.
- Each generated service includes an optimized Dockerfile utilizing multi-stage builds.
- This compiles a statically linked Go binary in a build stage (using
golang:alpine) and copies it into a tinyscratchimage for the final production container, resulting in extremely small and secure Docker images. - Essential runtime components like CA certificates are copied to enable secure outgoing connections.
- Service ports and other configurations are managed via environment variables within the Docker image, allowing easy deployment configuration.
- Save Time: Instantly scaffold all the repetitive setup code
- Best Practices: Follow idiomatic Go conventions and clean architecture
- Extendable: Easily add your business logic in services and controllers
- Environment Friendly: Automatically handles
.envloading per environment - Production Ready: Built-in graceful shutdown, logging, and Docker support
If you have Go installed, you can directly install the CLI tool using:
go install github.com/Muhammad-Ali-Khan9/gores/cmd@latestThis will compile and install the gores executable in your $GOPATH/bin or $HOME/go/bin directory. Make sure your Go bin path is in your PATH environment variable:
export PATH=$PATH:$(go env GOPATH)/binYou can then run:
- first initialze the project
gores init- then generate a microservice
gores generate myserviceYou can download pre-compiled binaries from the GitHub Releases page.
Available binaries:
gores-linux-amd64(Linux)gores-darwin-amd64(macOS)gores-windows-amd64.exe(Windows)
Usage example (Linux/macOS):
chmod +x gores-linux-amd64
./gores-linux-amd64 generate myserviceUsage example (Windows PowerShell):
.\gores-windows-amd64.exe generate myservicegores generate [service-name] [port]- service-name: The name of the microservice to generate (required).
- port: (Optional) port number. If omitted, the CLI automatically assigns the next available port starting from 8080.
This project is licensed under the Apache License 2.0.
You are free to use, modify, and distribute this software — including for commercial purposes — under the terms of the Apache License 2.0.
We welcome contributions! Please see CONTRIBUTING.md for guidelines on how to report issues, request features, and submit pull requests.