httptracer

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 10 Imported by: 0

README

Trace HTTP

Tracing HTTP Client

You can wrap *http.Client using log transport.

package main

import (
	"fmt"
	"io"
	"net/http"
	"github.com/yusufsyaifudin/ylog/httptracer"
)

type Library struct {
	HTTP *http.Client
}

func (l *Library) callExampleCom() (out []byte, err error) {
	resp, err := l.HTTP.Get("https://example.com")
	return io.ReadAll(resp.Body)
}

func New(client *http.Client) *Library {
	return &Library{
		HTTP: client,
	}
}

// calls will look like this

func main() {
	httpClient := &http.Client{
		Transport: httptracer.HTTPClient(nil),
	}

	lib := New(httpClient)
	out, err := lib.callExampleCom()
	if err != nil {
		panic(err)
	}

	fmt.Println(string(out))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPClientTracer

func NewHTTPClientTracer(roundTripper http.RoundTripper) http.RoundTripper

Types

type RoundTripper

type RoundTripper struct {
	Base http.RoundTripper
}

func (*RoundTripper) RoundTrip

func (r *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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