storj/examples/grpc-debug/main.go

54 lines
1.1 KiB
Go
Raw Normal View History

2019-01-24 20:15:10 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"fmt"
"github.com/spf13/pflag"
"google.golang.org/grpc"
"storj.io/storj/pkg/cfgstruct"
2019-01-30 20:47:21 +00:00
"storj.io/storj/pkg/identity"
2018-11-30 13:40:13 +00:00
"storj.io/storj/pkg/storj"
)
var (
targetAddr = pflag.String("target", "satellite.staging.storj.io:7777", "address of target")
2019-01-30 20:47:21 +00:00
identityConfig identity.Config
)
func init() {
cfgstruct.Bind(pflag.CommandLine, &identityConfig, cfgstruct.ConfDir("$HOME/.storj/gw"))
}
func main() {
ctx := context.Background()
pflag.Parse()
identity, err := identityConfig.Load()
if err != nil {
panic(err)
}
dialOption, err := identity.DialOption(storj.NodeID{})
if err != nil {
panic(err)
}
conn, err := grpc.Dial(*targetAddr, dialOption)
if err != nil {
panic(err)
}
fmt.Println(conn.GetState())
err = conn.Invoke(ctx, "NonExistentMethod", nil, nil)
if err != nil && err.Error() != `rpc error: code = ResourceExhausted desc = malformed method name: "NonExistentMethod"` {
fmt.Println(err)
}
fmt.Println(conn.GetState())
2018-09-28 19:08:44 +01:00
err = conn.Close()
if err != nil {
fmt.Println(err)
}
}