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

Overview

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."
}
Hello World (Golang)

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

Konyee 0 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

Nyoman Frastyawan 1 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

Pepcep 2 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

UCSD CSE 124 Fall 2021 0 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

Filipe Alves 10 May 11, 2022
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

Charles Weill 4k May 20, 2022
grpc + grpc gateway demo

grpc + grpc gateway demo

null 0 Nov 5, 2021
Example of using advanced gRPC error model

grpcerrors Example of using advanced gRPC error model

Will Andrews 0 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.

null 1 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.

Pierrick Martin 1 Feb 2, 2022
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.

atoy322 0 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,

Dmitry Chestnykh 1 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

Tien La 0 Dec 9, 2021
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.

The Strukture IDE 52 Feb 11, 2022
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

Visarut Phusua 17 Apr 27, 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

Pulumi 1 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

TDP Software 8 May 9, 2022
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

Shin'ya Ueoka 12 Mar 20, 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

Muhammad Naufal Rachfian Djamhur 0 Nov 27, 2021