GitPedia
rameshsunkara

rameshsunkara/go-rest-api-example

Production-ready Go REST APIs without the enterprise bloat

6 Releases
Latest: 7mo ago
Add Go 1.25 Flight Recorder Integration for Performance Debuggingv2.1.0Latest
rameshsunkararameshsunkaraยท7mo agoยทNovember 11, 2025
GitHub

๐Ÿ“ฆ Go 1.25 Flight Recorder Integration

  • โœ… Automatic Slow Request Detection - Captures execution traces for requests taking > 500ms
  • โœ… Zero Overhead When Disabled - Production-safe with opt-in configuration
  • โœ… Visual Trace Analysis - Use `go tool trace` to debug performance bottlenecks
  • โœ… Smart Buffer Management - Rolling 1 MiB buffer with 1-second retention window

๐Ÿ“ฆ Go 1.25 Upgrade

  • Upgraded from Go 1.24 โ†’ Go 1.25
  • Updated all dependencies to latest stable versions
  • Enhanced CI/CD pipeline for Go 1.25 support

๐Ÿ“ฆ Enhanced Developer Experience

  • ```bash
  • make trace TRACE_FILE=./traces/slow-request-GET-orders-1234567890.trace
  • ```
  • ๐ŸŽจ Enhanced README with emojis and visual improvements
  • ๐Ÿ“š Collapsible sections for better readability
  • ๐Ÿ“‹ Added `.env.example` template
  • New `enableTracing` environment variable

โœจ New Components

  • | Component | Description |
  • |-----------|-------------|
  • | `pkg/flightrecorder` | Flight recorder package with clean API |
  • | `.env.example` | Environment configuration template |
  • | `make trace` | Trace analysis command |

โœจ New Environment Variables

  • ```bash
  • enableTracing=true # Default: false
  • ```

๐Ÿ“ฆ Trace Configuration

  • Threshold: 500ms (requests slower than this are traced)
  • Buffer Size: 1 MiB (rolling buffer)
  • Retention: 1 second (minimum trace age)
  • Output Directory: `./traces/`

โšก ๐Ÿ“Š Performance Impact

  • | Mode | Memory Overhead | CPU Overhead | Notes |
  • |------|----------------|--------------|-------|
  • | Disabled | 0 bytes | 0% | Default, production-safe |
  • | Enabled | ~1 MiB | ~1-2% | Rolling buffer, minimal impact |
  • | Capturing | +file size | Negligible | Non-blocking write |

๐Ÿ“ฆ Quick Start

  • ```bash
  • git pull origin main
  • go mod tidy
  • cp .env.example .env
  • echo "enableTracing=true" >> .env
  • make start
  • ```

๐Ÿ“ฆ Analyzing Traces

  • ```bash
  • ls -lhtr ./traces/
  • make trace TRACE_FILE=./traces/slow-request-GET-orders-1762824976.trace
  • ```

๐Ÿ“ฆ Upgrading from v1.x

  • This release is backward compatible with no breaking changes.
  • ```bash
  • git pull origin main
  • go mod tidy
  • make start # Works immediately!
  • ```
  • ```bash
  • enableTracing=true
  • + 1 more

๐Ÿ“ Docker Users

  • ```bash
  • docker-compose down
  • docker-compose build
  • docker-compose up -d
  • ```

๐Ÿ“ฆ CI/CD

  • โœ… Updated to Go 1.25
  • โœ… golangci-lint v2.6.2 (latest stable)

๐Ÿ”’ ๐Ÿ” Security

  • No security vulnerabilities introduced
  • Flight recorder only active when explicitly enabled
  • Trace files contain execution data (review before sharing)
  • Added `.env` to `.gitignore` (prevents credential leaks)

๐Ÿ“ฆ ๐Ÿ“– Learning Resources

  • [Go 1.25 Flight Recorder Blog](https://go.dev/blog/flight-recorder)
  • [Go Tool Trace Documentation](https://pkg.go.dev/cmd/trace)
  • [Project README](./README.md)

๐Ÿ“ฆ ๐Ÿ’ฌ Feedback

  • I love to hear your feedback!
  • ๐Ÿ› Found a bug? [Open an issue](https://github.com/rameshsunkara/go-rest-api-example/issues)
  • ๐Ÿ’ก Have an idea? [Start a discussion](https://github.com/rameshsunkara/go-rest-api-example/discussions)
  • โญ Like this release? Give us a star!
  • ---
MongoDB Connection Architecture Refactorv2.0.0
rameshsunkararameshsunkaraยท9mo agoยทSeptember 28, 2025
GitHub

๐Ÿ“ฆ ๐Ÿ”ง **MongoDB Connection Architecture Redesign**

  • Complete refactor of MongoDB connection management from `internal/db` to dedicated `pkg/mongodb` package
  • New modular connection system with support for:
  • MongoDB and MongoDB+SRV connection schemes
  • Configurable options using functional pattern (replica sets, read preferences, write concerns)
  • Credential management via sidecar files
  • Connection URL masking for security
  • Comprehensive connection validation and error handling

๐Ÿ“ฆ ๐Ÿ“ฆ **Package Restructuring & Clean Architecture**

  • Migrated logger from `internal/logger` to `pkg/logger` for better reusability
  • Extracted configuration management to dedicated `internal/config` package
  • Improved separation of concerns with cleaner package boundaries

๐Ÿ“ฆ ๐Ÿ—๏ธ **Server & Application Improvements**

  • Enhanced graceful shutdown with proper context cancellation handling
  • Improved server lifecycle management with better error handling
  • Streamlined main application logic with cleaner separation of setup phases
  • Better configuration loading and validation

๐Ÿ“ฆ ๐Ÿ”„ **Dependency Updates**

  • MongoDB Driver 1.17.4 (latest stable release)
  • Gin Framework 1.11.0 (latest version with security fixes)
  • Updated all dependencies to latest stable versions for security and performance

โœจ **New Packages & Components**

  • ```
  • pkg/mongodb/ # MongoDB connection management
  • โ”œโ”€โ”€ connection.go # Connection manager implementation
  • โ”œโ”€โ”€ options.go # Connection options and functional patterns
  • โ”œโ”€โ”€ types.go # Type definitions and credentials
  • โ””โ”€โ”€ url.go # Connection URL building and validation
  • pkg/logger/ # Structured logging with zerolog
  • โ”œโ”€โ”€ logger.go # Logger interface and implementation
  • + 5 more

๐Ÿ—‘๏ธ **Removed/Refactored Components**

  • โŒ `internal/db/connection.go` โ†’ โœ… `pkg/mongodb/connection.go`
  • โŒ `internal/db/connectionURL.go` โ†’ โœ… `pkg/mongodb/url.go`
  • โŒ `internal/logger/` โ†’ โœ… `pkg/logger/`
  • โŒ `internal/util/` โ†’ โœ… `internal/utilities/`

๐Ÿ”’ ๐Ÿ”’ **Security Enhancements**

  • Input validation for all MongoDB connection parameters
  • Updated dependencies with latest security patches

๐Ÿ“ฆ ๐Ÿš€ **DevOps & CI/CD Improvements**

  • Enhanced Makefile with comprehensive test coverage reporting
  • Improved Docker configuration for local development
  • VS Code workspace settings for consistent development experience

๐Ÿ› ๐Ÿ› **Bug Fixes & Stability**

  • Improved error handling with proper error wrapping and context
  • Enhanced graceful shutdown preventing resource leaks

๐Ÿ’ฅ ๐Ÿ”„ **Breaking Changes**

  • โš ๏ธ API Changes (internal packages only - no public API changes):
  • MongoDB connection interfaces moved from `internal/db` to `pkg/mongodb`
  • Logger interface relocated to `pkg/logger`
  • Configuration structure updated in `internal/config`

๐Ÿ“ฆ ๐ŸŽฏ **Migration Guide**

  • For developers working with the codebase:
  • 1. Import path updates for MongoDB connections:
  • ```go
  • // Old
  • import "github.com/rameshsunkara/go-rest-api-example/internal/db"
  • // New
  • import "github.com/rameshsunkara/go-rest-api-example/pkg/mongodb"
  • ```
  • + 7 more
v1.1.1 Auto detect race conditionsv1.1.1
rameshsunkararameshsunkaraยท1y agoยทMay 24, 2025
GitHub

โœจ In addition to test changes

  • Injects logger to all appropriate functions
  • main.go is now modular and readable
  • Removed deferrun dep which was dealing with signals to cleanup
v1.1.0
rameshsunkararameshsunkaraยท1y agoยทMarch 25, 2025
GitHub

๐Ÿ“‹ Changes in this release:

  • 1. Upgraded Go version to 1.24: Updated the project to use the latest stable version of Go, ensuring better performance, security, and access to new language features.
  • 2. Upgraded golangci-lint to v2: Integrated the latest version of golangci-lint (v2), improving static code analysis and linting capabilities to catch potential issues early.
  • 3. Optimized Dockerfile with BuildKit: The Dockerfile now leverages Docker BuildKit for more efficient builds, including enhanced caching and faster layer processing.
  • 4. Parallelized Build Workflow: The CI build pipeline has been updated to run tests and Docker builds in parallel, reducing build time and improving overall workflow efficiency.
  • This release focuses on performance improvements, build optimizations, and code quality enhancements.
  • Full Changelog: https://github.com/rameshsunkara/go-rest-api-example/compare/v1.0.1...v1.1.0
Makefile and Test execution improvementsv1.0.1
rameshsunkararameshsunkaraยท1y agoยทNovember 24, 2024
GitHub

๐Ÿ“‹ Changes

  • Updated Makefile to improve readability and maintainability
  • Got rid of in memory mongodb usage for db test and used mtest from offical mongodb.
  • Tests are now executed in parallel
  • Updated redme to improve readbility
  • Increased code coverage
v1.0.0 New featuresv1.0.0
rameshsunkararameshsunkaraยท1y agoยทAugust 28, 2024
GitHub

โœจ API Features:

  • 1. OWASP Compliant [Open API 3 Spec](./OpenApi-v1.yaml)
  • 2. Middleware for
  • Logging : Helps in debugging and monitoring
  • Authentication : Placeholder for different authentication mechanisms
  • Tracing by Request ID : Helps in debugging
  • Panic Recovery : Helps in keeping the service up
  • Common Security Headers : Keeps the service secure
  • Query Params Validation : Helps in keeping the service secure
  • + 6 more

โœจ Go Application Features:

  • 1. Configuration Management through Environment Variables
  • 2. A Makefile to do all common tasks
  • 3. A Git Action to build, run tests, generate code coverage
  • 4. Integrated GO Formatter and Linter
  • 5. Mechanism to load secrets from Sidecar
  • 6. Enables connecting to multiple databases
  • 7. Follows the best practices for connecting to MongoDB
  • 8. Good mocking practises for Unit test patterns
  • + 1 more