debugutil

package
v0.0.0-...-bcea9b7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2021 License: MIT Imports: 7 Imported by: 0

README

Usage

PrettySprint creates a human readable representation of the value v.

Example
package main 

import (
	"github.com/donutloop/toolkit/debugutil"
	"log"
)

func main() {
    log.Println(debugutil.PrettySprint([]string{}))
}

PrettyResponseDump creates a human readable representation of the value http.Response.

Example
package main 

import (
	"github.com/donutloop/toolkit/debugutil"
	"log"
	"net/http"
)

func main() {

    resp := &http.Response{}
    s , err := debugutil.PrettySprintResponse(resp)
    if err != nil {
        log.Fatal(err)
    }    
    log.Println(s)
}

PrettyRequestDump creates a human readable representation of the value http.Request.

Example
package main 

import (
	"github.com/donutloop/toolkit/debugutil"
	"log"
	"net/http"
)

func main() {

    req := &http.Request{}
    s , err := debugutil.PrettySprintRequest(req)
    if err != nil {
        log.Fatal(err)
    }    
    log.Println(s)
}

LogRoundTripper which logs all requests (request and response dump)

Example
package main 

import (
	"github.com/donutloop/toolkit/debugutil"
	"net/http"
)

type logger struct {}

func (l logger) Errorf(format string, v ...interface{}) {
	log.Println(fmt.Sprintf(format, v...))
}
func (l logger) Infof(format string, v ...interface{}) {
	log.Println(fmt.Sprintf(format, v...))
}

func main() {

	httpClient := new(http.Client)
	httpClient.Transport = debugutil.NewLogRoundTripper(http.DefaultTransport, logger{}, true)

	response, err := httpClient.Get(server.URL)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogRoundTripper

func NewLogRoundTripper(roundTripper http.RoundTripper, logger logger, dumpBody bool) http.RoundTripper

RoundTripper returns a new http.RoundTripper which logs all requests (request and response dump). Should only be used for none production envs.

func PrettyDumpRequest

func PrettyDumpRequest(req *http.Request, body bool) ([]byte, error)

PrettyDumpRequest is like httputil.DumpRequest but dump is pretty formatted.

func PrettyDumpResponse

func PrettyDumpResponse(resp *http.Response, body bool) ([]byte, error)

PrettyDumpResponse is like httputil.DumpResponse but dump is pretty formatted.

func PrettySprint

func PrettySprint(v interface{}) string

PrettySprint generates a human readable representation of the value v.

Example
package main

import (
	"fmt"

	"github.com/donutloop/toolkit/debugutil"
)

func main() {
	str := debugutil.PrettySprint([]string{})
	fmt.Println(str)
}
Output:

[]string{
}

func PrettySprintRequest

func PrettySprintRequest(resp *http.Request) (string, error)

PrettySprintRequest is pretty printing a http request.

func PrettySprintResponse

func PrettySprintResponse(resp *http.Response) (string, error)

PrettyPrintResponse is pretty printing a http response.

Types

type LogRoundTripper

type LogRoundTripper struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

func (LogRoundTripper) RoundTrip

func (tr LogRoundTripper) RoundTrip(req *http.Request) (res *http.Response, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL