A lightweight and efficient Feature Flag Service built with Golang, Gin, PostgreSQL, Redis, and Swagger API Documentation. This service allows teams to manage and toggle feature flags dynamically for better continuous deployment and A/B testing strategies.
- ✅ JWT Authentication (User Registration & Login)
- ✅ Feature Flag Management (Create, Read, Update, Delete)
- ✅ PostgreSQL Database Integration
- ✅ Redis for Caching
- ✅ Swagger API Documentation
- ✅ Dockerized for Easy Deployment
- ✅ Mocked Database for CI/CD Testing
- API Base URL: https://feature-flag-service-production.up.railway.app/api
- Swagger Documentation: https://feature-flag-service-production.up.railway.app/swagger/index.html
feature-flag-service/
│-- internal/
│ │-- config/ # Database & Redis Configuration
│ │-- handlers/ # API Route Handlers
│ │-- middleware/ # Authentication Middleware
│ │-- models/ # Database Models
│ │-- tests/ # Unit & Integration Tests
│-- docs/ # Swagger Documentation
│-- main.go # Entry Point
│-- Dockerfile # Docker Build Config
│-- docker-compose.yml # Docker Compose Services
│-- README.md # Project Documentation
git clone https://github.com/your-username/feature-flag-service.git
cd feature-flag-service
Create a .env file in the root directory:
PORT=8080
DATABASE_URL=postgres://postgres:password@postgres:5432/feature_flags?sslmode=disable
REDIS_URL=redis:6379
JWT_SECRET=your_secret_key
docker-compose up --build
Ensure PostgreSQL and Redis are running, then:
go mod tidy
go run main.go
Method | Endpoint | Description |
---|---|---|
POST | /register |
Register a new user |
POST | /login |
Authenticate & get JWT |
Method | Endpoint | Description |
---|---|---|
POST | /api/flags |
Create a new feature flag |
GET | /api/flags |
Get all feature flags |
GET | /api/flags/{id} |
Get a single feature flag by ID |
PUT | /api/flags/{id} |
Update a feature flag |
DELETE | /api/flags/{id} |
Delete a feature flag |
📖 Swagger Documentation
- Once the service is running, access Swagger UI: 👉 http://localhost:8080/swagger/index.html
To run tests with database mocking:
TEST_MODE=true go test ./internal/tests -v
For full integration tests:
go test ./...
- Install Railway CLI:
curl -fsSL https://railway.app/install.sh | sh
- Initialize project:
railway init
- Deploy:
railway up
We welcome contributions! Feel free to open an issue or submit a pull request.
This project is MIT Licensed. See LICENSE
for details.
- Golang & Gin for backend development
- Swagger for API Documentation
- PostgreSQL & Redis for database management
- Railway & Docker for seamless deployment