Skip to content

n3xpect/production-ready-microservice-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example Microservice

A Go-based microservice with Couchbase integration, metrics, logging and OpenTelemetry support.

Overview

This service provides REST API endpoints for managing products, utilizing Couchbase as the primary database and implementing distributed tracing with OpenTelemetry.

Prerequisites

  • Go 1.23.4
  • Docker and Docker Compose
  • Couchbase Server

Tech Stack

  • Language: Go
  • Database: Couchbase
  • Distributed Tracing: OpenTelemetry, Jaeger
  • Container: Docker
  • Config: Viper
  • Logger: Zap
  • Metrics: Prometheus
  • Monitoring: Grafana

Project Structure

├── app
│ └── healthcheck
│── └── health.go
│ └── product
│── └── create_product_handler.go
│── └── get_product_handler.go
│── └── repository.go
├── config
│ └── config.yaml -- App Configuration File
├── domain
│ └── product.go
├── infra
│ └── couchbase
│── └── repository.go
│ └── postgres
│── └── repository.go
├── pkg
│ └── config
│── └── config.go
│ └── log
│── └── log.go
├── Dockerfile
├── docker-compose.yml
├── main.go

Getting Started

  1. Clone the repository:

    git clone https://github.com/mstrYoda/production-ready-microservice-example.git
  2. Start the required services using Docker Compose:

    docker-compose up -d
  3. Run the application:

    go run main.go

API Endpoints

Products

  • POST /products - Create a new product
  • GET /products/{id} - Retrieve a product by ID

Configuration

Configuration is managed through environment variables and config files and can be set in the docker-compose.yml file. Key configuration parameters include:

  • Couchbase connection settings
  • OpenTelemetry configuration
  • Application port

Development

Building the Docker Image

docker build -t product-service .

Running Tests

go test ./...

Observability

This service implements OpenTelemetry for distributed tracing, allowing you to monitor and debug requests across your distributed system.

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

[Add your license information here]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 96.0%
  • Dockerfile 4.0%