71 lines
1.4 KiB
Markdown
71 lines
1.4 KiB
Markdown
# Golang Project Template
|
|
|
|
A production-ready Go project template with Docker builds, CI/CD pipelines, and best practices.
|
|
|
|
## Features
|
|
|
|
- **Standard Layout**: Follows Go project layout standards (`cmd`, `internal`).
|
|
- **Graceful Shutdown**: `main.go` implements signal handling and context cancellation.
|
|
- **Structured Logging**: Uses `log/slog`.
|
|
- **Docker**: Multi-stage `Dockerfile` using `distroless` for secure, small images.
|
|
- **CI/CD**: GitHub Actions for linting, testing, building, and releasing (with GoReleaser).
|
|
- **Tooling**: `Makefile` for common tasks and `golangci-lint` configuration.
|
|
|
|
## Prerequisites
|
|
|
|
- [Go](https://go.dev/) 1.23+
|
|
- [Docker](https://www.docker.com/)
|
|
- [Make](https://www.gnu.org/software/make/)
|
|
|
|
## Getting Started
|
|
|
|
### Build and Run
|
|
|
|
```bash
|
|
# Build binary
|
|
make build
|
|
|
|
# Run application
|
|
make run
|
|
```
|
|
|
|
### Testing
|
|
|
|
```bash
|
|
make test
|
|
```
|
|
|
|
### Linting
|
|
|
|
```bash
|
|
make lint
|
|
```
|
|
|
|
## Docker
|
|
|
|
Build the Docker image:
|
|
|
|
```bash
|
|
make docker-build
|
|
```
|
|
|
|
Run the container:
|
|
|
|
```bash
|
|
docker run --rm -p 8080:8080 app:latest
|
|
```
|
|
|
|
## CI/CD
|
|
|
|
The project includes GitHub Actions workflows:
|
|
|
|
- **CI (`ci.yml`)**: Runs on `main` and PRs. Validates formatting, linting, tests, and builds.
|
|
- **Release (`release.yml`)**: Runs on tags (`v*`). Creates a GitHub Release and pushes the Docker image to GHCR.
|
|
|
|
## Project Structure
|
|
|
|
- `cmd/app`: Main application entry point.
|
|
- `internal`: Private application code.
|
|
- `build`: Build artifacts.
|
|
- `.github`: CI/CD workflows.
|