github.com/theQRL/go-zond@v0.1.1/rpc/client_opt_test.go (about)

     1  package rpc_test
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"time"
     7  
     8  	"github.com/theQRL/go-zond/rpc"
     9  )
    10  
    11  // This example configures a HTTP-based RPC client with two options - one setting the
    12  // overall request timeout, the other adding a custom HTTP header to all requests.
    13  func ExampleDialOptions() {
    14  	tokenHeader := rpc.WithHeader("x-token", "foo")
    15  	httpClient := rpc.WithHTTPClient(&http.Client{
    16  		Timeout: 10 * time.Second,
    17  	})
    18  
    19  	ctx := context.Background()
    20  	c, err := rpc.DialOptions(ctx, "http://rpc.example.com", httpClient, tokenHeader)
    21  	if err != nil {
    22  		panic(err)
    23  	}
    24  	c.Close()
    25  }