Reconnect gRPC Method
Parâmetros
url
cadeia de caracteres
OBRIGATÓRIO
Carregando...
Devoluções
erro
objeto
Carregando...
Pedido
1pacote principal23importar (4"contexto"5"crypto/tls"6"fmt"78"github.com/fbsobreira/gotron-sdk/pkg/client"9"google.golang.grpc"10"google.golang.grpc"11)121314// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token15// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678916// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}17// token will be : abcde1234567891819var token = "O_SEU_TOKEN"20var endpoint = "YOUR_ENDPOINT:50051"212223tipo auth estrutura {24token cadeia de caracteres25}2627func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]cadeia de caracteres, erro) {28retornar mapa[string]string{29«x-token»: um.token,30}, nil31}3233func (a *auth) RequireTransportSecurity() bool {34retornar false35}3637func main() {38opts := []grpc.DialOption{39grpc.WithTransportCredentials(credenciais.NewTLS(&tls.Config{})),40grpc.WithPerRPCCredentials(&auth{token}),41}42conn := client.NewGrpcClient(endpoint)43if err := conn.Start(opts...); err != nil {44panic(err)45}4647conn.Stop()48fmt.Println("Successfully stopped")4950err := conn.Reconnect(endpoint)51se err != nil {52fmt.Printf("Error reconnecting: %v\n", err)53return54}5556fmt.Println("Successfully reconnected")57}
1pacote principal23importar (4"contexto"5"crypto/tls"6"fmt"78"github.com/fbsobreira/gotron-sdk/pkg/client"9"google.golang.grpc"10"google.golang.grpc"11)121314// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token15// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678916// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}17// token will be : abcde1234567891819var token = "O_SEU_TOKEN"20var endpoint = "YOUR_ENDPOINT:50051"212223tipo auth estrutura {24token cadeia de caracteres25}2627func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]cadeia de caracteres, erro) {28retornar mapa[string]string{29«x-token»: um.token,30}, nil31}3233func (a *auth) RequireTransportSecurity() bool {34retornar false35}3637func main() {38opts := []grpc.DialOption{39grpc.WithTransportCredentials(credenciais.NewTLS(&tls.Config{})),40grpc.WithPerRPCCredentials(&auth{token}),41}42conn := client.NewGrpcClient(endpoint)43if err := conn.Start(opts...); err != nil {44panic(err)45}4647conn.Stop()48fmt.Println("Successfully stopped")4950err := conn.Reconnect(endpoint)51se err != nil {52fmt.Printf("Error reconnecting: %v\n", err)53return54}5556fmt.Println("Successfully reconnected")57}
Ainda não tem uma conta?
Crieendpoint seuendpoint Quicknode endpoint segundos e comece a desenvolver
Comece gratuitamente