client.go 536 B

123456789101112131415161718192021
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/longjoy/micro-go-course/section18/pb"
  6. "google.golang.org/grpc"
  7. )
  8. func main() {
  9. serviceAddress := "127.0.0.1:8080"
  10. conn, err := grpc.Dial(serviceAddress, grpc.WithInsecure())
  11. if err != nil {
  12. panic("connect error")
  13. }
  14. defer conn.Close()
  15. userClient := pb.NewUserServiceClient(conn)
  16. stringReq := &pb.LoginRequest{Username: "admin", Password: "admin"}
  17. reply, _ := userClient.CheckPassword(context.Background(), stringReq)
  18. fmt.Printf("CheckPassword ret is %s\n", reply.Ret)
  19. }