A production-ready Go API following the Standard Go Project Layout with a focus on DevSecOps and security automation.
- Standard Layout: Separates entry point (
cmd/) from business logic (internal/). - DevSecOps Pipeline: Automated Linting, SAST, SCA, and Container Scanning via GitHub Actions.
- Secure Docker Image: Multi-stage build using a Distroless base image to minimize attack surface.
- RESTful API: Built with the Gin Gonic framework.
- Go: v1.24 or higher
- Docker: For containerization
- (Optional) Local Security Tools:
golangci-lint(Linting)gosec(Security Scan)govulncheck(Vulnerability Scan)
go run cmd/api/main.goThe server will start at http://localhost:8080.
Run all unit tests with race detection and coverage:
go test -v -race -cover ./...go mod tidyUse these commands locally to catch issues before pushing to GitHub.
Requires golangci-lint.
golangci-lint runScans code for security flaws like hardcoded secrets or SQL injection.
go install github.com/securego/gosec/v2/cmd/gosec@latest
gosec ./...Checks for known vulnerabilities in your dependencies.
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...This project uses swag to generate Swagger 2.0 documentation from code comments.
go install github.com/swaggo/swag/cmd/swag@latestRun this command from the project root whenever you update API comments:
swag init -g cmd/api/main.goThe documentation will be updated in the docs/ directory.
Start the API and navigate to:
http://localhost:8080/swagger/index.html
docker build -t go-api .docker run -p 8080:8080 go-apiThis project includes a pre-push hook that runs tests and security scans automatically before every push. This helps ensure that no broken or insecure code is pushed to the remote repository.
To install the local hooks, run the following command:
cp scripts/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-pushIf you ever need to bypass the hook, use the --no-verify flag:
git push --no-verifyThe project includes a GitHub Actions workflow in .github/workflows/devsecops.yml that automatically runs on every push and pull request to main:
- Test & Lint: Runs
golangci-lintandgo test. - Security Scan: Runs
gosec(SAST) andgovulncheck(SCA). - Docker Scan: Builds the image and scans it with Trivy for vulnerabilities.
| Method | Endpoint | Description |
|---|---|---|
| GET | /albums |
Get all albums |
| GET | /albums/:id |
Get album by ID |
| POST | /albums |
Add a new album |