github.com/blend/go-sdk@v1.20220411.3/examples/r2/transport/main.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package main
     9  
    10  import (
    11  	"fmt"
    12  	"net/http"
    13  	"os"
    14  	"time"
    15  
    16  	"github.com/blend/go-sdk/r2"
    17  )
    18  
    19  func main() {
    20  	//create external transport reference
    21  	transport := &http.Transport{}
    22  
    23  	// pass to the request
    24  	req := r2.New("https://google.com/robots.txt", r2.OptTransport(transport))
    25  
    26  	var res *http.Response
    27  	var err error
    28  	for x := 0; x < 10; x++ {
    29  		res, err = req.Discard()
    30  		if err != nil {
    31  			fmt.Fprintf(os.Stderr, "%v\n", err)
    32  		} else {
    33  			fmt.Fprintf(os.Stdout, "%v %v %v\n", res.StatusCode, res.Status, res.ContentLength)
    34  		}
    35  		time.Sleep(500 * time.Millisecond)
    36  	}
    37  	fmt.Println("Done")
    38  }