github.com/InjectiveLabs/sdk-go@v1.53.0/examples/explorer/7_StreamBlocks/example.go (about) 1 package main 2 3 import ( 4 "context" 5 "encoding/json" 6 "fmt" 7 8 "github.com/InjectiveLabs/sdk-go/client/common" 9 explorerclient "github.com/InjectiveLabs/sdk-go/client/explorer" 10 ) 11 12 func main() { 13 network := common.LoadNetwork("testnet", "lb") 14 explorerClient, err := explorerclient.NewExplorerClient(network) 15 if err != nil { 16 panic(err) 17 } 18 19 ctx := context.Background() 20 stream, err := explorerClient.StreamBlocks(ctx) 21 if err != nil { 22 panic(err) 23 } 24 25 for { 26 select { 27 case <-ctx.Done(): 28 return 29 default: 30 res, err := stream.Recv() 31 if err != nil { 32 panic(err) 33 } 34 str, _ := json.MarshalIndent(res, "", " ") 35 fmt.Print(string(str)) 36 } 37 } 38 }