github.com/mre-fog/trillianxx@v1.1.2-0.20180615153820-ae375a99d36a/examples/vmap/trillian_map_client/main.go (about) 1 // Copyright 2016 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // The trillian_map_client binary performs a trivial map operation. 16 package main 17 18 import ( 19 "context" 20 "flag" 21 22 "github.com/golang/glog" 23 "github.com/google/trillian" 24 "github.com/google/trillian/testonly" 25 "google.golang.org/grpc" 26 ) 27 28 var server = flag.String("server", "localhost:8091", "Server address:port") 29 30 func main() { 31 flag.Parse() 32 defer glog.Flush() 33 34 conn, err := grpc.Dial(*server, grpc.WithInsecure()) 35 if err != nil { 36 glog.Fatal(err) 37 } 38 defer conn.Close() 39 40 c := trillian.NewTrillianMapClient(conn) 41 42 key := "This Is A Key" 43 index := testonly.HashKey(key) 44 45 { 46 req := &trillian.SetMapLeavesRequest{ 47 MapId: 1, 48 Leaves: []*trillian.MapLeaf{ 49 { 50 Index: index, 51 LeafHash: []byte("This is a leaf hash"), 52 LeafValue: []byte("This is a leaf value"), 53 ExtraData: []byte("This is some extra data"), 54 }, 55 }, 56 } 57 resp, err := c.SetLeaves(context.Background(), req) 58 if err != nil { 59 glog.Error(err) 60 return 61 } 62 glog.Infof("Got SetLeaves response: %+v", resp) 63 } 64 65 { 66 req := &trillian.GetMapLeavesRequest{ 67 MapId: 1, 68 Index: [][]byte{ 69 index, 70 }, 71 } 72 resp, err := c.GetLeaves(context.Background(), req) 73 if err != nil { 74 glog.Error(err) 75 } 76 glog.Infof("Got GetLeaves response: %+v", resp) 77 } 78 }