currency

command
v0.0.0-...-7fc8bb1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: MIT Imports: 8 Imported by: 0

README

Currency Service

A simple example to understand gRPC in golang!

Directory Structure

.
├── currency.proto
├── main.go
├── Makefile
├── protos
│   ├── currency_grpc.pb.go
│   └── currency.pb.go
├── README.md
└── server
    └── currency.go

Testing

To test the system install grpccurl which is a command line tool which can interact with gRPC API's

Link to the repo is here!

go install github.com/fullstorydev/grpcurl/cmd/grpcurl

Run the server
  • Command: go run main.go
List Services
  • Command: grpcurl --plaintext localhost:8080 list
  • Output:
    Currency
    grpc.reflection.v1alpha.ServerReflection
    
List Methods
  • Command: grpcurl --plaintext localhost:8080 list Currency
  • Output: Currency.GetRate
Method detail for GetRate
  • Command: grpcurl --plaintext localhost:8080 describe Currency.GetRate
  • Output:
    Currency.GetRate is a method:
    rpc GetRate ( .RateRequest ) returns ( .RateResponse );
    
RateRequest detail
  • Command: grpcurl --plaintext localhost:8080 describe .RateRequest
  • Output:
    RateRequest is a message:
    message RateRequest {
        string Base = 1;
        string Destination = 2;
    }
    
RateResponse detail
  • Command: grpcurl --plaintext localhost:8080 describe .RateResponse
  • Output:
    RateResponse is a message:
    message RateResponse {
        float rate = 1;
    }
    
Execute a request
  • Command: grpcurl --plaintext -d '{"Base":"USD","Destination":"INR"}' localhost:8080 Currency.GetRate
  • Output:
    {
        "rate": 0.5
    }
    

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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