This is a Go-based project that provides a structured backend implementation. It includes a Makefile for automation, linting, testing, and dependency management.
Ensure you have the following installed:
- Go (latest stable version)
- Git
golangci-lintandgoimports(installed automatically)- jq (for checking outdated dependencies)
git clone https://github.com/fuunshi/go-backend-template.git
cd go-backend-templatebash script.shRun the following command to install dependencies, format code, lint, and build the project:
make setupThis command:
✅ Installs required Go dependencies
✅ Installs golangci-lint and goimports (if missing)
✅ Formats the code (go fmt, goimports)
✅ Runs lint checks
✅ Checks for outdated dependencies
✅ Builds the project
make devRuns the application directly without compiling it first.
make runCompiles and runs the application.
| Command | Description |
|---|---|
make setup |
Install dependencies, format, lint, and build the project. |
make build |
Compile the application into bin/server. |
make run |
Build and run the application. |
make dev |
Run without building (useful for development). |
make test |
Run all tests. |
make lint |
Run static analysis using golangci-lint. |
make lint-fix |
Auto-fix linting issues. |
make fmt |
Format code using go fmt and goimports. |
make tidy |
Ensure go.mod and go.sum are up to date. |
make outdated |
Check for outdated dependencies. |
make clean |
Remove compiled binaries. |
make migrate |
Run database migrations using CLI commands. |
make swagger |
Generate Swagger API documentation. |
make mock |
Generate mocks for testing. |
make seed |
Seed the database with initial data. |
make install-tools |
Install required Go tools such as golangci-lint, goimports, and swag. |
.
├── docker-compose.yaml
├── docs
│ ├── docs.go
│ ├── swagger.json
│ └── swagger.yaml
├── go.mod
├── go.sum
├── lefthook.yml
├── Makefile
├── README.md
├── script.sh
└── src
├── api
│ ├── auth
│ │ ├── controller.go
│ │ ├── repository.go
│ │ ├── routes.go
│ │ ├── schema.go
│ │ └── service.go
│ └── user
│ ├── controller.go
│ ├── dao.go
│ ├── model.go
│ ├── repository.go
│ ├── routes.go
│ ├── schema.go
│ └── service.go
├── cmd
│ ├── cli
│ │ ├── main.go
│ │ ├── migrate.go
│ │ └── seed.go
│ └── http
│ ├── main.go
│ └── server.go
├── common
│ ├── model
│ │ └── model.go
│ └── schema
│ └── schema.go
├── config
│ ├── database.go
│ └── env
│ └── env.go
├── logger
│ └── logger.go
├── middlewares
│ ├── jwt_auth.go
│ ├── rate_limit.go
│ └── validation.go
├── service
│ └── response.go
├── tests
│ └── user_test.go
└── utils
└── jwt_util.go
If golangci-lint or goimports is missing, you can manually install them:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install golang.org/x/tools/cmd/goimports@latestRun:
make tidyThis cleans up go.mod and go.sum.
- Built with ❤️ using Go
- Static analysis with golangci-lint