kondohiroki / go-grpc-boilerplate

A project boilerplate to make a gRPC server using Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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/protoc-gen-go@v1.28
    $ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
  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 "john@email.com"
  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


Languages

Language:Go 94.1%Language:Makefile 3.2%Language:Shell 1.3%Language:PowerShell 1.2%Language:Dockerfile 0.2%