helloworldgrpc

package
v0.4.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 7 Imported by: 0

README

helloworldgrpc

This example illustrates how to expose helloworld as gRPC APIs.

Prerequisites

  • Protocol buffer compiler v3
  • Go plugins for the protocol compiler

See gRPC Go Quickstart for installation instructions.

Generate the code

$ go generate

Test the server

Run the server:

$ go run cmd/main.go
2021/07/04 18:18:00 server listening at [::]:8080

Consume by grpcurl:

$ grpcurl -plaintext -d '{"name": "Tracey"}' :8080 pb.Service/SayHello
{
  "message": "Hello Tracey"
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeEndpointOfSayHello

func MakeEndpointOfSayHello(s Service) endpoint.Endpoint

MakeEndpointOfSayHello creates the endpoint for s.SayHello.

func NewGRPCServer

func NewGRPCServer(svc Service, codecs grpccodec.Codecs) pb.ServiceServer

func ValidateSayHelloRequest

func ValidateSayHelloRequest(newSchema func(*SayHelloRequest) validating.Schema) httpoption.Validator

ValidateSayHelloRequest creates a validator for SayHelloRequest.

Types

type Greeter

type Greeter struct{}

func (*Greeter) SayHello

func (g *Greeter) SayHello(ctx context.Context, name string) (string, error)

type SayHelloRequest

type SayHelloRequest struct {
	Name string `json:"name"`
}

type SayHelloResponse

type SayHelloResponse struct {
	Message string `json:"message"`
	Err     error  `json:"-"`
}

func (*SayHelloResponse) Body

func (r *SayHelloResponse) Body() interface{}

func (*SayHelloResponse) Failed

func (r *SayHelloResponse) Failed() error

Failed implements endpoint.Failer.

type Service

type Service interface {
	// SayHello says hello to the given name.
	//kun:grpc
	SayHello(ctx context.Context, name string) (message string, err error)
}

Service is used for saying hello.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL