ref: d9a4ea91abaa7581ef09e5ee04bcc08613abef0e
server/grpc/metric-grpc-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 37 38 39 40 41 42 43 44 45 46 47 48 |
/** * Yats - yats * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * * @author Paolo Lulli <kevwe.com> * @copyright Paolo Lulli 2024 */ package grpc import ( "context" "log" "time" "yats-server/proto" "google.golang.org/grpc" ) func mains() { conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure(), grpc.WithBlock()) if err != nil { log.Fatalf("did not connect: %v", err) } defer conn.Close() c := proto.NewYatsGrpcServiceClient(conn) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() item := &proto.Metric{IdClient: "DefaultIdClient", Name: "Item 1", Mtime: time.Now().UnixMilli(), Value: "This is the value"} res, err := c.CreateMetric(ctx, &proto.CreateMetricRequest{Metric: item}) if err != nil { log.Fatalf("could not create item: %v", err) } log.Printf("Item created: %v", res.GetMetric()) /* // Read an item resRead, err := c.ReadMetric(ctx, &proto.ReadMetricRequest{Id: "1"}) if err != nil { log.Fatalf("could not read item: %v", err) } log.Printf("Item read: %v", resRead.GetMetric()) */ } |