This repository provides a template for implementing a gRPC API in Go, which can also be accessed via REST. It demonstrates a well-structured project layout that adheres to best practices in Go development.
- gRPC API: Fast and efficient remote procedure calls.
- RESTful Access: Access the same functionality through RESTful endpoints.
- Best Practices: Organized project structure for maintainability and scalability.
- Integrated Testing: Unit and integration tests to ensure code quality.
- Protobuf Definitions: Clear and structured API definitions using Protocol Buffers.
- Go 1.18 or later
- Protobuf compiler (
protoc
)brew install protobuf # for mac
pip install protobuf # for linux
- gRPC and related Go libraries
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest go install google.golang.org/protobuf/cmd/protoc-gen-go@latest go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
- Pre-commit
brew install pre-commit # for mac
pip install pre-commit # for linux
-
Clone the repository:
git clone https://github.com/TimRutte/api.git cd api
-
Install dependencies:
make tidy
-
Install necessary Go tools:
go install golang.org/x/tools/cmd/goimports@latest go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest go install honnef.co/go/tools/cmd/staticcheck@latest
To build and run the application, use the following commands:
make build-linux
make build-darwin
make build-windows
make run
To run the application in a Docker container, build the image:
make docker-build
Then run the container:
make docker-run
Unit tests and integration tests are included in the project. To run the tests with vulnerability check, use:
make test
To run only the unit tests:
make test-only
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.