This is a Go backend service built using clean architecture principles. It provides a robust foundation for building scalable and maintainable web applications.
- Clean Architecture implementation
- HTTP server using standard
net/http
package - PostgreSQL database integration with
sqlx
- Middleware support (CORS, XSS, Logging, etc.)
- Structured logging with Zap
- Configuration management
- Graceful shutdown
- Health check endpoints
- Request ID tracking
- Response compression
- Security headers
- Input validation
- Error handling
├── cmd
│ └── main.go # Application entry point
├── internal
│ ├── entity # Business objects
│ ├── model # Database models
│ ├── repository
│ │ ├── interfaces # Repository interfaces
│ │ └── impl # Repository implementations
│ ├── usecase
│ │ ├── interfaces # UseCase interfaces
│ │ └── impl # UseCase implementations
│ ├── delivery
│ │ ├── http # HTTP handlers
│ │ └── grpc # gRPC handlers (optional)
│ └── middleware # Custom middleware
├── pkg
│ ├── logger # Logging package
│ └── utils # Utility functions
└── config # Configuration files
- Go 1.21 or later
- PostgreSQL
- Make (optional)
- Clone the repository
git clone https://github.com/yourusername/go-skeleton.git
cd go-skeleton
- Install dependencies
go mod download
- Configure the application
- Copy
config/config.json.example
toconfig/config.json
- Update the configuration values as needed
- Create the database
CREATE DATABASE myapp;
- Run the application
go run cmd/main.go
POST /users
- Create a new userGET /users/{id}
- Get user by IDPUT /users/{id}
- Update userDELETE /users/{id}
- Delete userGET /users
- List users (with pagination)
GET /health
- Check application health
The application can be configured using the config/config.json
file. The following configuration options are available:
{
"server": {
"port": "8080",
"readTimeout": "15s",
"writeTimeout": "15s",
"idleTimeout": "60s"
},
"database": {
"driver": "postgres",
"dsn": "postgres://postgres:postgres@localhost:5432/myapp?sslmode=disable",
"maxOpenConns": 25,
"maxIdleConns": 25,
"connMaxLifetime": "5m",
"queryTimeout": "10s"
},
"logger": {
"level": "debug",
"file": "logs/app.log"
},
"security": {
"allowedOrigins": ["*"],
"allowedMethods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
"allowedHeaders": ["Content-Type", "Authorization"],
"maxRequestSize": 1048576,
"rateLimit": {
"requests": 100,
"window": "1m"
}
}
}
- Create entity in
internal/entity
- Create repository interface in
internal/repository/interfaces
- Implement repository in
internal/repository/impl
- Create use case interface in
internal/usecase/interfaces
- Implement use case in
internal/usecase/impl
- Create HTTP handler in
internal/delivery/http
- Register routes in
cmd/main.go
go test ./...
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.