lorem_grpc

package
v0.0.0-...-d5bb415 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2017 License: GPL-3.0 Imports: 8 Imported by: 3

README

lorem-grpc

This is simple service module. Only for showing the micro service with gRPC protocol The purpose for this service is only generating lorem ipsum paragraph and return the payload.

I am fully using all three functions from the golorem library.

Required libraries

go get github.com/go-kit/kit
go get github.com/drhodes/golorem
go get github.com/gorilla/mux

pb

Protocol buffer module. The place to create proto files. Download protoc from here Then execute go get -u github.com/golang/protobuf/{proto,protoc-gen-go}

Note: don't forget to add GOBIN on your PATH

To generate protobuf file into go file: protoc lorem.proto --go_out=plugins=grpc:.

service.go

Business logic will be put here

endpoint.go

Endpoint will be created here

model.go

Encode and Decode json

transport.go

Implement interface from protocol buffer

execute
cd $GOPATH

#Running grpc server
go run src/github.com/ru-rocker/gokit-playground/lorem-grpc/server/server_grpc_main.go

#Running client
go run src/github.com/ru-rocker/gokit-playground/lorem-grpc/client/cmd/client_grpc_main.go lorem sentence 10 20

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRequestTypeNotFound = errors.New("Request type only valid for word, sentence and paragraph")
)

Functions

func DecodeGRPCLoremRequest

func DecodeGRPCLoremRequest(_ context.Context, r interface{}) (interface{}, error)

func DecodeGRPCLoremResponse

func DecodeGRPCLoremResponse(_ context.Context, r interface{}) (interface{}, error)

func EncodeGRPCLoremRequest

func EncodeGRPCLoremRequest(_ context.Context, r interface{}) (interface{}, error)

Encode and Decode Lorem Request

func EncodeGRPCLoremResponse

func EncodeGRPCLoremResponse(_ context.Context, r interface{}) (interface{}, error)

Encode and Decode Lorem Response

func MakeLoremEndpoint

func MakeLoremEndpoint(svc Service) endpoint.Endpoint

creating Lorem Ipsum Endpoint

func NewGRPCServer

func NewGRPCServer(_ context.Context, endpoint Endpoints) pb.LoremServer

create new grpc server

Types

type Endpoints

type Endpoints struct {
	LoremEndpoint endpoint.Endpoint
}

endpoints wrapper

func (Endpoints) Lorem

func (e Endpoints) Lorem(ctx context.Context, requestType string, min, max int) (string, error)

Wrapping Endpoints as a Service implementation. Will be used in gRPC client

type LoremRequest

type LoremRequest struct {
	RequestType string
	Min         int32
	Max         int32
}

request

type LoremResponse

type LoremResponse struct {
	Message string `json:"message"`
	Err     string `json:"err,omitempty"`
}

response

type LoremService

type LoremService struct {
}

Implement service with empty struct

func (LoremService) Lorem

func (LoremService) Lorem(_ context.Context, requestType string, min, max int) (string, error)

Implement service functions

type Service

type Service interface {
	// generate a word with at least min letters and at most max letters.
	Lorem(ctx context.Context, requestType string, min, max int) (string, error)
}

Define service interface

Directories

Path Synopsis
cmd
Package pb is a generated protocol buffer package.
Package pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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