client

package
v0.0.77 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package client provides a HTTP client implementation. This client is opinionated and comes with good defaults.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Safe added in v0.0.8

func Safe(l *slog.Logger, timeout ...time.Duration) *http.Client

Safe creates a http client that has some good defaults & is safe from server-side request forgery (SSRF). It also logs requests and responses using log.Logger The timeout is optional.

Example
package main

import (
	"context"
	"os"

	"github.com/komuw/ong/client"
	"github.com/komuw/ong/log"
)

func main() {
	l := log.New(context.Background(), os.Stdout, 7)

	cli := client.Safe(l)
	// This is the AWS metadata url.
	url := "http://169.254.169.254/latest/meta-data"
	_, _ = cli.Get(url)

	// This will log something like:
	// {"time":"2023-02-03T18:54:13.300137216Z","level":"ERROR","source":"client.go:108","msg":"http_client","err":"dial tcp 169.254.169.254:80: ong/client: address 169.254.169.254 IsLinkLocalUnicast","method":"GET","url":"http://169.254.169.254/latest/meta-data","durationMS":0,"logID":"DYGY3eedgARMAyXZ"}
}
Output:

func Unsafe added in v0.0.8

func Unsafe(l *slog.Logger, timeout ...time.Duration) *http.Client

Unsafe creates a http client that has some good defaults & is NOT safe from server-side request forgery (SSRF). It also logs requests and responses using log.Logger The timeout is optional

Types

This section is empty.

Jump to

Keyboard shortcuts

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