Skip to content

A project boilerplate to make a gRPC server using Go

Notifications You must be signed in to change notification settings

kondohiroki/go-grpc-boilerplate

Repository files navigation

go-grpc-boilerplate 🚀

Getting Started

Prerequisites

  • Go 1.21
  • Docker
  • sonar-scanner - for coverage test in local
    brew install sonar-scanner

Installation

  1. Clone the repo
    git clone https://github.com/kondohiroki/go-grpc-boilerplate
  2. Install Go dependencies
    go mod tidy
  3. Copy the default configuration file
    cp config/config.example.yaml config/config.yaml
  4. Start the database
    docker compose up -d
  5. Migrate database
    go run main.go migrate
  6. Run the application
    # Run normally
    go run main.go serve:grpc-api
    
    # Run with hot reload
    air serve:grpc-api
  7. Testing (optional)
    # Run unit-test
    make unit-test
    
    # Run api-test
    make api-test
    
    # Create sonar scret
    touch .sonar.secret
    echo "your-sonar-token" > .sonar.secret
    
    # Add secret to .sonar.secret
    # Get from sonar web

Protobuf

  1. Install protobuf compiler

    brew install protobuf
  2. Install the protocol compiler plugins for Go

    $ go install google.golang.org/protobuf/cmd/[email protected]
    $ go install google.golang.org/grpc/cmd/[email protected]
  3. Update your PATH so that the protoc compiler can find the plugins:

    export PATH="$PATH:$(go env GOPATH)/bin"
  4. Compile the proto file to generate the gRPC code

    make pb
  5. Make sure all dependencies are installed

    go mod tidy

Before commit

  1. Please correct your git username and email
    git config user.name "John Doe"
    git config user.email "[email protected]"
  2. Please squash&rebase your commits
    # Make sure that base branch is up-to-date
    git checkout main
    git fetch
    git pull
    
    # Back to your branch
    git checkout <your-feature-branch>
    
    # =====> SQUASH <=====
    git reset $(git merge-base origin/main $(git branch --show-current))
    git add -A
    git commit -m "[ISSUE-ID] Add auth api configuration"
    git push -f
    
    # =====> REBASE <=====
    git rebase origin/main
    
    # After resolving conflicts, continue the rebase process
    git rebase --continue
    
    # Force-push the rebased feature branch to the remote repository
    git push -f

About

A project boilerplate to make a gRPC server using Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published