...

Source file src/github.com/henvic/httpretty/example/client/main.go

Documentation: github.com/henvic/httpretty/example/client

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"os"
     7  
     8  	"github.com/henvic/httpretty"
     9  )
    10  
    11  func main() {
    12  	logger := &httpretty.Logger{
    13  		Time:           true,
    14  		TLS:            true,
    15  		RequestHeader:  true,
    16  		RequestBody:    true,
    17  		ResponseHeader: true,
    18  		ResponseBody:   true,
    19  		Colors:         true, // erase line if you don't like colors
    20  		Formatters:     []httpretty.Formatter{&httpretty.JSONFormatter{}},
    21  	}
    22  
    23  	client := &http.Client{
    24  		Transport: logger.RoundTripper(http.DefaultTransport),
    25  	}
    26  
    27  	if _, err := client.Get("https://www.google.com/"); err != nil {
    28  		fmt.Fprintf(os.Stderr, "%+v\n", err)
    29  		os.Exit(1)
    30  	}
    31  }
    32  

View as plain text