matrixprotobuf

git clone git://archive.git.mtrnord.blog/MTRNord/matrixprotobuf.git
Log | Files | Refs | README | LICENSE

client.go (1300B)


      1 package main
      2 
      3 import (
      4 	pb "github.com/Nordgedanken/MatrixProtoBuf/matrixProtos"
      5 	"golang.org/x/net/context"
      6 	"google.golang.org/grpc"
      7 	"log"
      8 )
      9 
     10 const (
     11 	address = "localhost:50051"
     12 )
     13 
     14 func main() {
     15 	// Set up a connection to the server.
     16 	conn, err := grpc.Dial(address, grpc.WithInsecure())
     17 	if err != nil {
     18 		log.Fatalf("did not connect: %v", err)
     19 	}
     20 	defer conn.Close()
     21 
     22 	Login(conn)
     23 	GetHSVersions(conn)
     24 }
     25 
     26 func Login(conn *grpc.ClientConn) {
     27 	lc := pb.NewLoginServiceClient(conn)
     28 
     29 	// Contact the server and print out its response.
     30 	//TODO REMOVE MY PASSWORD!!!!!
     31 	lr, err := lc.Login(context.Background(), &pb.LoginRequest{Type: "m.login.password", User: "@MTRNord:matrix.org", Password: "", Medium: "", Address: "matrix.org"})
     32 	if err != nil {
     33 		log.Fatalf("could not get Login: %v - %v", grpc.Code(err), grpc.ErrorDesc(err))
     34 	}
     35 	log.Printf("Greeting: %s", lr.String())
     36 }
     37 
     38 func GetHSVersions(conn *grpc.ClientConn) {
     39 	vc := pb.NewVersionsServiceClient(conn)
     40 
     41 	// Contact the server and print out its response.
     42 	vr, err := vc.Versions(context.Background(), &pb.VersionRequest{Address: "matrix.org"})
     43 	if err != nil {
     44 		log.Fatalf("could not get Version: %v - %v", grpc.Code(err), grpc.ErrorDesc(err))
     45 	}
     46 
     47 	log.Println("Versions:")
     48 	for _, k := range vr.Versions {
     49 		log.Println(k.Version)
     50 	}
     51 }