Example hello-world service uses go-fx-grpc-starter boilerplate code

About

Example hello-world service uses https://github.com/srlk/go-fx-grpc-starter boilerplate code.

Implementation

A hello world grpc service is created with hello.proto definition

syntax = "proto3";
option go_package = "github.com/srlk/go-fx-grpc-hello-world/hello";

package hello;

message HelloRequest {
  string from = 1;
  string to = 2;
}

message HelloResponse {
  string greeting = 1;
}

service HelloService {
  rpc SayHello(HelloRequest) returns (HelloResponse) {}
}

HelloService code is generated using protoc tool.

AppService in appservice.go registers and implements HelloService service.

// appservice.go

// Service provider - can receive args to be injected by uber/fx
func NewAppService() fxgrpc.FxGrpcServiceDefinition {
	return AppService{}
}

// Service object
type AppService struct {
	UnimplementedHelloServiceServer
}

// Register hello service
func (me AppService) RegisterService(grpcServer *grpc.Server) {
	RegisterHelloServiceServer(grpcServer, &me)

}

// Implement hello service
func (me *AppService) SayHello(ctx context.Context, req *HelloRequest) (*HelloResponse, error) {
	return &HelloResponse{
		Greeting: fmt.Sprintf("Hello %s! I am %s.", req.From, req.To),
	}, nil
}

Main method of main.go basically teaches uber/fx how to create the service and run it.

// main.go

func main() {
	fxapp.StartApp(
		fxgrpc.Module,
		fx.Provide(NewAppService), // Provide Service
	)
}

Modifying Service

Service can be which can be modified and recreated by updating hello.proto file.

After modification it's necessary to re-run protoc to re-generate service code. (or alternatively running genservice.sh)

Calling Service

Example app can be run directly

go run main.go appservice.go

While the server is running, the service can be called using grpcurl tool via command line with below example request. (or alternatively running grpc-cli.sh)

grpcurl \
    -import-path ./hello \
    -proto hello.proto  \
    -plaintext \
    -d '{"from": "Serol", "to": "Erol"}' localhost:9090 hello.HelloService.SayHello

Response:

{
  "greeting": "Hello Serol! I am Erol."
}
Similar Resources

QuickAbeHiroshi - The golang program to open a web site which is the fastest in the world

QuickAbeHiroshi - The golang program to open a web site which is the fastest in the world

The golang program to open a web site which is the fastest in the world.

Jan 2, 2022

Onmap - Go package onmap puts pins on a world map image

onmap Go package onmap puts pins on a world map image. The images (mercator.jpg,

Feb 3, 2022

A Simple Bank Web Service implemented in Go, HTTP & GRPC, PostgreSQL, Docker, Kubernetes, GitHub Actions CI

simple-bank Based on this Backend Master Class by TECH SCHOOL: https://youtube.com/playlist?list=PLy_6D98if3ULEtXtNSY_2qN21VCKgoQAE Requirements Insta

Dec 9, 2021

A Visual Go REST API boilerplate builder.

A Visual Go REST API boilerplate builder.

A Visual Go REST API boilerplate builder. The boilerplate builder will export a Go web server with 0 dependencies, besides the ones you add.

Jul 8, 2022

A boilerplate for Go fiber versioning

A boilerplate for Go fiber versioning

Fiber Versioning Boilerplate Prerequisite Make sure you have the following installed outside the current project directory and available in your GOPAT

Nov 18, 2022

A boilerplate showing how to create a Pulumi component provider written in Go

xyz Pulumi Component Provider (Go) This repo is a boilerplate showing how to create a Pulumi component provider written in Go. You can search-replace

Mar 4, 2022

Golang Fiber boilerplate with MySQL resource.

Fibo - Go Fiber API Boilerplate A starter project with Golang, Fiber and Gorm Golang Fiber boilerplate with MySQL resource. Supports multiple configur

Nov 1, 2022

Boilerplate for building a monolighic Go and React application

Boilerplate for building a monolighic Go and React application

Monolithic Go and React Application Boilerplate This repository provides a simple and monolithic service with a server written in Go and frontend with

Dec 19, 2022

Go Clean Architecture Boilerplate

Go Clean-Architecture Simple Go Clean-Architecture Boilerplate Overview The purpose of the template is to show: How to organize a project and prevent

Nov 27, 2021
Hello World (Golang)

Name(hello-world-go) サブパッケージをインポートして、サブパッケージに属する関数を使用して HelloWorld を表示する。

Dec 28, 2021
A boilerplate/starter project for quickly building APIs using Golang with Clean Architechture
A boilerplate/starter project for quickly building APIs using Golang with Clean Architechture

A boilerplate/starter project for quickly building APIs using Golang with Clean Architechture

Mar 2, 2022
World-banks - Go Library for retrieving world banks.

World banks Go Library for retrieving world banks. Quick start To install: go get github.com/pepcep/world-banks Usage There are several ways of utili

Jan 11, 2022
UCSD CSE 124 Fall 2021 Project 3 Starter Code

Surfstore This is the starter code for Module 3: Surfstore. Before you get started, make sure you understand the following 2 things about Go. (These w

May 15, 2022
Golang service boilerplate using best practices

go-boilerplate Golang service boilerplate using best practices. Responsibility: Register (CRUD) and Login Users with JWT. Dependencies Gin-Gonic Swagg

May 11, 2022
Automatically generate Go test boilerplate from your source code.
Automatically generate Go test boilerplate from your source code.

gotests gotests makes writing Go tests easy. It's a Golang commandline tool that generates table driven tests based on its target source files' functi

Jan 3, 2023
grpc + grpc gateway demo

grpc + grpc gateway demo

Nov 5, 2021
Example of using advanced gRPC error model

grpcerrors Example of using advanced gRPC error model

Nov 19, 2021
This example implements a basic example of how to create your own modules, and how to call them from other modules

This example implements a basic example of how to create your own modules, and how to call them from other modules. In addition, an example of how to do unit tests is developed.

Feb 1, 2022
Run The World. Command aggregator output. Define many services watch them in one place.

Run The World. Command aggregator output. Define many services watch them in one place.

Feb 2, 2022