A RESTful API built with Go and Gin framework, following clean architecture principles and best practices.
- 🚀 Gin Framework - Fast HTTP web framework
- 📝 Structured Logging - Using zerolog for efficient logging
- 🔒 CORS Support - Cross-origin resource sharing
- 🏗️ Clean Architecture - Organized project structure
- 📊 Health Checks - Built-in health and readiness endpoints
- 🔧 Environment Configuration - Easy configuration management
- 📋 Standard REST API - Following REST conventions
tutuplapak/
├── main.go # Application entry point
├── go.mod # Go module file
├── .env.example # Environment variables template
├── README.md # This file
└── internal/ # Private application code
├── config/ # Configuration management
│ └── config.go
├── handlers/ # HTTP request handlers
│ ├── health.go
│ └── user.go
├── middleware/ # HTTP middleware
│ ├── cors.go
│ ├── logger.go
│ └── recovery.go
├── models/ # Data models
│ ├── response.go
│ └── user.go
└── routes/ # Route definitions
└── routes.go
- Go 1.25.0 or higher
- Git
-
Clone the repository
git clone <your-repo-url> cd tutuplapak
-
Install dependencies
go mod tidy
-
Set up environment variables
cp .env.example .env # Edit .env with your configuration -
Run the application
go run main.go
The API will be available at http://localhost:8080
GET /api/v1/health/- Health statusGET /api/v1/health/ready- Readiness check
GET /api/v1/users/- Get all users (with pagination)GET /api/v1/users/:id- Get user by IDPOST /api/v1/users/- Create new userPUT /api/v1/users/:id- Update userDELETE /api/v1/users/:id- Delete user
{
"id": 1,
"email": "name@name.com",
"name": "John Doe",
"preference": "metric",
"weightUnit": "kg",
"heightUnit": "cm",
"weight": 75.5,
"height": 180.0,
"imageUri": "https://example.com/image.jpg"
}Note: All fields except id and email can be null when empty.
GET /- API information
| Variable | Description | Default |
|---|---|---|
ENVIRONMENT |
Application environment | development |
PORT |
Server port | 8080 |
DATABASE_URL |
Database connection string | - |
JWT_SECRET |
JWT signing secret | your-secret-key |
CORS_ALLOWED_ORIGINS |
Allowed CORS origins | * |
- Create a new handler in
internal/handlers/ - Define models in
internal/models/if needed - Add routes in
internal/routes/routes.go - Update main.go to initialize the new handler
// internal/handlers/product.go
type ProductHandler struct{}
func (h *ProductHandler) GetProducts(c *gin.Context) {
// Implementation
}// internal/routes/routes.go
products := v1.Group("/products")
{
products.GET("/", productHandler.GetProducts)
}# Build the application
go build -o tutuplapak main.go
# Run the binary
./tutuplapakCreate a Dockerfile:
FROM golang:1.25-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o tutuplapak main.go
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/fitbyte .
CMD ["./tutuplapak"]- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
- Add CI/CD pipeline