https://github.com/anisstefler/go-microservice-template
https://github.com/anisstefler/go-microservice-template
boilerplate buf containers gitops google-cloud http http-server json json-api kafka key-value-store nodejs proto protobuf rest-api rust rust-crate starter-kit
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/anisstefler/go-microservice-template
- Owner: AnisStefler
- License: mit
- Created: 2025-06-21T22:26:47.000Z (6 days ago)
- Default Branch: main
- Last Pushed: 2025-06-22T02:19:42.000Z (6 days ago)
- Last Synced: 2025-06-22T03:25:54.930Z (5 days ago)
- Topics: boilerplate, buf, containers, gitops, google-cloud, http, http-server, json, json-api, kafka, key-value-store, nodejs, proto, protobuf, rest-api, rust, rust-crate, starter-kit
- Homepage: https://anisstefler.github.io
- Size: 4.88 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Microservice Template: A Modern Approach to Building Microservices π
  
Welcome to the **Go Microservice Template** repository! This project offers a modern structure for building microservices using Go. It includes REST and gRPC APIs, integrates OpenTelemetry for observability, and supports PostgreSQL as the database. The template is also ready for deployment on Kubernetes.
You can find the latest releases [here](https://github.com/AnisStefler/go-microservice-template/releases). Download and execute the necessary files to get started with your microservice.
## Table of Contents
- [Features](#features)
- [Technologies Used](#technologies-used)
- [Getting Started](#getting-started)
- [Folder Structure](#folder-structure)
- [Configuration](#configuration)
- [Running the Service](#running-the-service)
- [Testing](#testing)
- [Deployment](#deployment)
- [Contributing](#contributing)
- [License](#license)## Features
- **REST and gRPC APIs**: Easily create and manage both types of services.
- **OpenTelemetry Integration**: Monitor and trace requests for better observability.
- **PostgreSQL Support**: Use a reliable relational database for your data needs.
- **Ent ORM**: Simplify database interactions with an easy-to-use Object Relational Mapper.
- **Kubernetes Ready**: Deploy your microservice in a Kubernetes environment without hassle.
- **Prometheus Integration**: Monitor service metrics and performance.## Technologies Used
This template utilizes several key technologies:
- **Go**: The programming language used for building the microservice.
- **gRPC**: A modern RPC framework for high-performance communication.
- **Kubernetes**: For container orchestration and management.
- **PostgreSQL**: A powerful, open-source relational database.
- **Ent**: An ORM for Go that simplifies database operations.
- **OpenTelemetry**: A framework for observability and monitoring.
- **Prometheus**: A monitoring system for collecting metrics.## Getting Started
To get started with the Go Microservice Template, follow these steps:
1. **Clone the Repository**: Use the following command to clone the repo to your local machine.
```bash
git clone https://github.com/AnisStefler/go-microservice-template.git
```2. **Navigate to the Directory**:
```bash
cd go-microservice-template
```3. **Install Dependencies**: Make sure you have Go installed. Then, run:
```bash
go mod tidy
```4. **Configure the Environment**: Set up your environment variables. You can find a sample `.env` file in the repository.
5. **Run Migrations**: Use Ent to run database migrations.
```bash
go run ent/migrate.go
```6. **Start the Service**: Run the following command to start the microservice.
```bash
go run main.go
```## Folder Structure
Hereβs an overview of the folder structure:
```
go-microservice-template/
βββ cmd/ # Main application entry point
βββ ent/ # Ent ORM files
βββ internal/ # Business logic and service implementations
βββ pkg/ # Shared utilities and helper functions
βββ configs/ # Configuration files
βββ migrations/ # Database migration files
βββ tests/ # Unit and integration tests
```## Configuration
The configuration for the application is managed through environment variables. You can create a `.env` file in the root directory. Hereβs an example of the variables you might include:
```
DATABASE_URL=postgres://user:password@localhost:5432/mydb
GRPC_PORT=50051
REST_PORT=8080
```Make sure to replace the values with your actual database credentials and desired ports.
## Running the Service
To run the service, ensure your PostgreSQL database is up and running. Then, execute:
```bash
go run main.go
```The service will start on the configured ports. You can access the REST API at `http://localhost:8080` and the gRPC service at `localhost:50051`.
## Testing
To run tests, navigate to the root of the project and execute:
```bash
go test ./...
```This command will run all the tests in the repository. Make sure to write tests for your service logic to ensure reliability.
## Deployment
To deploy the microservice on Kubernetes, you need to create the necessary Kubernetes manifests. You can find sample manifests in the `k8s/` directory.
1. **Build the Docker Image**:
```bash
docker build -t my-microservice:latest .
```2. **Push the Image to a Container Registry**:
```bash
docker push my-microservice:latest
```3. **Deploy to Kubernetes**:
```bash
kubectl apply -f k8s/
```This will create the necessary deployments, services, and other resources in your Kubernetes cluster.
## Contributing
We welcome contributions! If you want to contribute, please follow these steps:
1. Fork the repository.
2. Create a new branch (`git checkout -b feature-branch`).
3. Make your changes and commit them (`git commit -m 'Add new feature'`).
4. Push to the branch (`git push origin feature-branch`).
5. Create a pull request.Please ensure your code follows the existing style and includes tests where applicable.
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
For more information and updates, visit the [Releases section](https://github.com/AnisStefler/go-microservice-template/releases). Download and execute the necessary files to kickstart your microservice journey!