Skip to content

Go template for building a gRPC API microservice with REST support, showcasing best practices and a clean project structure.

License

Notifications You must be signed in to change notification settings

timrutte/go-grpc-api-template

Repository files navigation

gRPC API Template

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.

Table of Contents

Features

  • 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.

Getting Started

Prerequisites

  • 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

Installation

  1. Clone the repository:

    git clone https://github.com/TimRutte/api.git
    cd api
  2. Install dependencies:

    make tidy
  3. 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

Building and Running

To build and run the application, use the following commands:

make build-linux
make build-darwin
make build-windows
make run

Docker

To run the application in a Docker container, build the image:

make docker-build

Then run the container:

make docker-run

Testing

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

Contributing

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.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Go template for building a gRPC API microservice with REST support, showcasing best practices and a clean project structure.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published