go HTTP client that makes it plain simple to configure TLS, basic auth, retries on specific errors, keep-alive connections, logging, timeouts etc.

goat

Goat, is an HTTP client built on top of a standard Go http package, that is extremely easy to configure; no googling required. The idea is similar to https://github.com/vspaz/pyclient it supports out of the box:

  • TLS,
  • basic auth
  • delayed retries on specific errors
  • timeouts (connection, read, idle etc.)
  • keep-alive connections
  • extra helpers
  • logging
  • etc.

still, if you don't wish any configuration, you can you use it as is with default parameters. Please, see the examples below:

package main

import (
	"github.com/vspaz/goat/pkg/ghttp"
	"log"
)

type HttpBinGetResponse struct {
	Args struct {
	} `json:"args"`
	Headers struct {
		AcceptEncoding string `json:"Accept-Encoding"`
		Authorization  string `json:"Authorization"`
		Host           string `json:"Host"`
		UserAgent      string `json:"User-Agent"`
		XAmznTraceId   string `json:"X-Amzn-Trace-Id"`
	} `json:"headers"`
	Origin string `json:"origin"`
	Url    string `json:"url"`
}

func main() {
	client := ghttp.NewClientBuilder().
		Host("https://httpbin.org"). // optional 
		Auth("user", "user-password"). // optional 
		Tls("cert.pem", "cert.pem", "ca.crt"). // optional 
		TlsHandshakeTimeout(10.0). // optional
		UserAgent("goat"). // optional
		Retry(3, []int{500, 503}). // optional 
		Delay(0.5). // optional
		ResponseTimeout(10.0). // optional
		ConnectionTimeout(2.0). // optional 
		HeadersReadTimeout(2.0). // optional 
		KeepAlive(60 * 2). //optional
		LogLevel("info"). // optional 
		Build()

	resp, err := client.DoGet("/get", nil)
	if err != nil {
		log.Fatal(err)
	}
	log.Println(resp.StatusCode)
	log.Println(resp.ToString())

	deserializedBody := HttpBinGetResponse{}
	resp.FromJson(&deserializedBody)

	// or just run with default parameters
	client = ghttp.NewClientBuilder().Build()
	resp, err = client.DoGet("https://httpbin.org", nil)
	if err != nil {
		log.Fatal(err)
	}
	log.Println(resp.IsOk())
	log.Println(resp.ToString())
}
Similar Resources

Share plain text, images and files in Local area network.

LAN-Share Share plain text, images and files in Local area network. Usage $ lan-share -h Usage of lan-share: -addr string Listen on address

Jan 25, 2022

Fork of Go stdlib's net/http that works with alternative TLS libraries like refraction-networking/utls.

github.com/ooni/oohttp This repository contains a fork of Go's standard library net/http package including patches to allow using this HTTP code with

Sep 29, 2022

Transparent TLS and HTTP proxy serve and operate on all 65535 ports, with domain regex whitelist and rest api control

goshkan Transparent TLS and HTTP proxy serve & operating on all 65535 ports, with domain regex whitelist and rest api control tls and http on same por

Nov 5, 2022

Golang tool to configure the Barco CX-20 station in one click. T

Golang tool to configure the Barco CX-20 station in one click. T

Golang tool to configure the Barco CX-20 station in one click. The CX-20 connect wireless to existing huddle room camera, speakerphones and audio peripherals, saving time and maximizing efficiency.

Aug 29, 2022

Using Wireshark to decrypt TLS gRPC Client-Server protobuf messages

Using Wireshark to decrypt TLS gRPC Client-Server protobuf messages

Using Wireshark to decrypt TLS gRPC Client-Server protobuf messages Sample client server in golang that demonstrates how to decode protobuf messages f

Sep 8, 2022

Simple endpoint to create chat for specific application.

About Chat System Simple endpoint to create chat for specific application. Note This endpoints depend on chat-system repoistory, so you ought to run c

Nov 20, 2021

Simple utility to set the WSL2 subnet to a specific range

WSL subnet utility This is a small Go utility to set the WSL2 host and subnet. It achieves this by: deleting the existing WSL network creating a new o

Oct 22, 2022

Limit-order-book - Limit order books keep records of orders for a given symbol to be traded

Limit Order Book Limit order books keep records of orders for a given symbol to

Jan 17, 2022

Go-ipfs-pinner - The pinner system is responsible for keeping track of which objects a user wants to keep stored locally

go-ipfs-pinner Background The pinner system is responsible for keeping track of

Jan 18, 2022
Http-server - A HTTP server and can be accessed via TLS and non-TLS mode

Application server.go runs a HTTP/HTTPS server on the port 9090. It gives you 4

Feb 3, 2022
Peoplenect - Keep track of all your professional connections on your machine

Peoplenect Keep track of all your professional connections. TODO Create database

Jun 2, 2022
Http-logging-proxy - A HTTP Logging Proxy For Golang

http-logging-proxy HTTP Logging Proxy Description This project builds a simple r

Aug 1, 2022
Use ICMP requests to check the alive subnet.

Doge-AliveCheck Use ICMP requests to check the alive subnet. Build go build -ldflags "-s -w" -trimpath Usage Doge-AliveCheck.exe

Nov 11, 2022
Todo-app-grpc - Go/GRPC codebase containing RealWorld examples (CRUD, auth, advanced patterns, etc)

Go/GRPC codebase containing RealWorld examples (CRUD, auth, advanced patterns, e

Oct 12, 2022
Timeouts for popular Go packages

Go Timeouts An unresponsive service can be worse than a down one. It can tie up your entire system if not handled properly. All network requests shoul

Aug 23, 2022
viagh.NewHTTPClient returns a *http.Client that makes API requests via the gh command.

viagh viagh.NewHTTPClient returns a *http.Client that makes API requests via the gh command. Why viagh? When writing a GitHub CLI extension, the exten

Dec 24, 2021
go-jsonc provides a way to work with commented json by converting it to plain json.

JSON with comments for GO Decodes a "commented json" to "json". Provided, the input must be a valid jsonc document. Supports io.Reader With this, we c

Apr 6, 2022