/
client.go
36 lines (30 loc) · 803 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"log"
pb "github.com/narenaryan/datafiles"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
const (
address = "localhost:50051"
)
func main() {
// Set up a connection to the server.
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
log.Fatalf("Did not connect: %v", err)
}
defer conn.Close()
c := pb.NewMoneyTransactionClient(conn)
// Prepare data. Get this from clients like Frontend or App
from := "1234"
to := "5678"
amount := float32(1250.75)
// Contact the server and print out its response.
r, err := c.MakeTransaction(context.Background(), &pb.TransactionRequest{From: from,
To: to, Amount: amount})
if err != nil {
log.Fatalf("Could not transact: %v", err)
}
log.Printf("Transaction confirmed: %t", r.Confirmation)
}