ref: 89777a764361663ff609027a4848f29a7134fe05
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 49 50 |
/** * 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{InsecureIdClient: "DefaultIdClient", Name: "Item 1", Mtime: time.Now().UnixMilli(), Value: "This is the value"} item := &proto.Metric{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()) */ } |