Blame view

test/tlsclient.go 605 Bytes
66502d8d   zhangqijia   从token中获取uid
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
  package main
  
  import (
  	"context"
  	"google.golang.org/grpc"
  	"google.golang.org/grpc/credentials"
  	"log"
  	"pro2d/protos/pb"
  )
  
  func main() {
  	var opts []grpc.DialOption
  	creds, err := credentials.NewClientTLSFromFile("keys/server.pem", "pro2d")
  	if err != nil {
  		log.Fatal(err)
  		return
  	}
  	opts = append(opts, grpc.WithTransportCredentials(creds))
  	conn, err := grpc.Dial("localhost:8948", opts...)
  
  	helloClient := pb.NewHelloClient(conn)
  	rsp, err := helloClient.SayHello(context.TODO(), &pb.HelloWorld{Msg: "hello world"})
  	if err != nil {
  		log.Fatal(err)
  	}
  
  	log.Printf("sayhello rsp: %v", rsp)
  }