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

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