goreq

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2019 License: BSD-2-Clause Imports: 10 Imported by: 3

README

goreq

Is a http client wrapper

Features:

  • logging request in CURL format
  • logging request time
  • repeat request via repeat strategy
  • has repeat timeout
  • validate request before call
  • custom response error strategy

Documentation

Index

Constants

View Source
const DefaultTimeout = 30

Default request timeout

Variables

This section is empty.

Functions

func BuildCURL

func BuildCURL(request *HttpRequest) string

Build curl for logging

func Ensure

func Ensure(request HttpRequest) (*http.Response, []byte, error)

Ensure request

Types

type HttpRequest

type HttpRequest struct {
	//Host service label. For messages
	Label string
	//Default Http client
	Client *http.Client
	//Service host
	Host string
	//Http method. GET, POST, PUT etc
	Method string
	//Remote endpoint
	Url string
	//Http headers
	Headers http.Header
	//Http body
	Body []byte
	//Count of retry attempts
	RetryCount uint
	//Retry timeout. Default 30s
	RetryTimeout time.Duration
	//Retry strategy callback
	RetryStrategy func(response *http.Response) bool
	//Response error
	ResponseErrorStrategy func(response *http.Response, url string, service string) error
	//Logger. Implements RequestLogger
	Logger Logger
	//How many body bytes must be logged
	//0 - all body will be logged
	LogBodySize int
}

Each request performs via struct bellow

func (HttpRequest) EnsureJSON

func (r HttpRequest) EnsureJSON(method string, url string, header http.Header, body interface{}, dto interface{}) (*http.Response, error)

Ensure JSON request

type Logger

type Logger interface {
	Print(v ...interface{})
	Println(v ...interface{})
	Printf(format string, v ...interface{})
}

Request logger interface Implement default logger methods

Jump to

Keyboard shortcuts

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