call ping
parent
b21c0788fa
commit
b06500eff1
|
@ -1,14 +1,60 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/vilmibm/hermeticum/proto"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
var (
|
||||
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
|
||||
caFile = flag.String("ca_file", "", "The file containing the CA root cert file")
|
||||
serverAddr = flag.String("addr", "localhost:6666", "The server address in the format of host:port")
|
||||
serverHostOverride = flag.String("server_host_override", "x.test.example.com", "The server name used to verify the hostname returned by the TLS handshake")
|
||||
)
|
||||
|
||||
func _main() error {
|
||||
fmt.Println("lol TODO make a client")
|
||||
var opts []grpc.DialOption
|
||||
if *tls {
|
||||
return errors.New("TODO tls unsupported")
|
||||
/*
|
||||
if *caFile == "" {
|
||||
*caFile = data.Path("x509/ca_cert.pem")
|
||||
}
|
||||
creds, err := credentials.NewClientTLSFromFile(*caFile, *serverHostOverride)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create TLS credentials %v", err)
|
||||
}
|
||||
opts = append(opts, grpc.WithTransportCredentials(creds))
|
||||
*/
|
||||
} else {
|
||||
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
}
|
||||
|
||||
// TODO do a ping against server
|
||||
conn, err := grpc.Dial(*serverAddr, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("fail to dial: %w", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := proto.NewGameWorldClient(conn)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
pong, err := client.Ping(ctx, &proto.SessionInfo{})
|
||||
if err != nil {
|
||||
log.Fatalf("%v.Ping -> %v", client, err)
|
||||
}
|
||||
|
||||
log.Printf("%#v", pong)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"github.com/vilmibm/hermeticum/proto"
|
||||
"google.golang.org/grpc"
|
||||
|
@ -80,7 +79,5 @@ func main() {
|
|||
err := _main()
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue