Skip to content

ForwardStar/grpc-example-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Install Prerequisites

Install Go, etcd and goreman:

sudo apt-get install golang
sudo apt-get install etcd

For goreman, download from https://github.com/mattn/goreman/releases/tag/v0.3.11 and put binaries under PATH.

Initialize Standalone etcd Server and Service

etcd

Initialize Multi-member Cluster

goreman -f Procfile start

This pulls up 3 etcd nodes. To stop one of them:

goreman run stop etcd1

Run Server

Open another terminal and run the scripts:

go run server/server.go

Run Client

go run client/client.go

Regenerate gRPC Code

protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    service/protoservices.proto

Database APIs

You can do database management in client/client.go.

The message struct RequestMsg has three fields: Operation, Key, Value.

Operation has 4 possible values: SetKV, GetKey, DeleteKey, GetListValues.

For SetKV, it sets a key-value pair in the database. You need to provide Key, Value fields in RequestMsg.

For GetKey, it returns the value of the requested key. You need to provide the field Key in RequestMsg.

For DeleteKey, it clears a key-value pair. You need to provide the field Key in RequestMsg.

For GetListValues, it returns a list of all values in the database.

Although Value passed to the server should be strings, you can define your own struct in client/client.go and stringify it before request.

See client/client.go for examples.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages