github.com/IBM-Bluemix/golang-openssl-wrapper@v0.0.0-20160104220506-7f2d5273b515/examples/httpstransport.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/IBM-Bluemix/golang-openssl-wrapper/ssl"
     6  	"io/ioutil"
     7  	"net/http"
     8  	"strings"
     9  )
    10  
    11  func main() {
    12  	// Create a new HTTPS client
    13  	client := http.Client{
    14  		// Use our transport for FIPS compliant OpenSSL
    15  		Transport: ssl.NewHTTPSTransport(nil),
    16  	}
    17  
    18  	// Call HTTP GET on the client
    19  	response, err := client.Get("https://httpbin.org/ip")
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  
    24  	// Defer closing the response body so it isn't forgotten.
    25  	defer response.Body.Close()
    26  
    27  	// Read the entire body
    28  	body, _ := ioutil.ReadAll(response.Body)
    29  
    30  	// Convert body to string and trim newlines
    31  	bstring := strings.Trim(string(body), "\n")
    32  
    33  	// Print response
    34  	fmt.Printf("https://httpbin.org/ip response:\n%s\n", bstring)
    35  }