fluent

package module
v0.0.0-...-392b95b Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2014 License: MIT Imports: 8 Imported by: 6

README

Fluent

Fluent HTTP client for Golang. With timeout, retries and exponential back-off support.

Usage:

package main

import (
  "fmt"
  "github.com/lafikl/fluent"
  "time"
)

func main() {
  req := fluent.New()
  req.Post("http://example.com").
    InitialInterval(time.Duration(time.Millisecond)).
    Json([]int{1, 3, 4}).
    Retry(3)

  res, err := req.Send()

  if err != nil {
    fmt.Println(err)
  }

  fmt.Println("donne ", res)

  // They can be separated if you don't like chaining ;)
  // for example:
  // req.Get("http://example.com")
  // req.Retry(3)
}

http://godoc.org/github.com/lafikl/fluent

Documentation

Overview

Fluent HTTP client for Golang. With timeout, retries and exponential back-off support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	// contains filtered or unexported fields
}

func New

func New() *Request

Create a new request

func (*Request) Body

func (f *Request) Body(b io.Reader) *Request

Whatever you pass to it will be passed to http.NewRequest

func (*Request) Delete

func (f *Request) Delete(url string) *Request

Same as f.Post but the method is `DELETE`

func (*Request) Get

func (f *Request) Get(url string) *Request

Same as f.Post but the method is `GET`

func (*Request) InitialInterval

func (f *Request) InitialInterval(t time.Duration) *Request

The initial interval for the request backoff operation.

the default is 500 * time.Millisecond

For more information http://godoc.org/github.com/cenkalti/backoff#ExponentialBackOff

func (*Request) Json

func (f *Request) Json(j interface{}) *Request

A handy method for sending json without needing to Marshal it yourself This method will override whatever you pass to f.Body And it sets the content-type to "application/json"

func (*Request) MaxElapsedTime

func (f *Request) MaxElapsedTime(me time.Duration) *Request

Set the Max Elapsed Time for the backoff.

The default is 15 * time.Minute.

For more information http://godoc.org/github.com/cenkalti/backoff#ExponentialBackOff

func (*Request) MaxInterval

func (f *Request) MaxInterval(mi time.Duration) *Request

Set the Max Interval for the backoff.

The default is 60 * time.Second

For more information http://godoc.org/github.com/cenkalti/backoff#ExponentialBackOff

func (*Request) Method

func (f *Request) Method(method string) *Request

Set the request Method You probably want to use the methods [Post, Get, Patch, Delete, Put]

func (*Request) Multiplier

func (f *Request) Multiplier(m float64) *Request

Set the Multiplier for the backoff.

The default is 1.5.

For more information http://godoc.org/github.com/cenkalti/backoff#ExponentialBackOff

func (*Request) Patch

func (f *Request) Patch(url string) *Request

Same as f.Post but the method is `PATCH`

func (*Request) Post

func (f *Request) Post(url string) *Request

This is a shorthand method that calls f.Method with `POST` and calls f.Url with the url you give to her

func (*Request) Proxy

func (f *Request) Proxy(p string) *Request

Set a HTTP proxy

func (*Request) Put

func (f *Request) Put(url string) *Request

Same as f.Post but the method is `PUT`

func (*Request) RandomizationFactor

func (f *Request) RandomizationFactor(rf float64) *Request

Set the Randomization factor for the backoff.

the default is 0.5

For more information http://godoc.org/github.com/cenkalti/backoff#ExponentialBackOff

func (*Request) Retry

func (f *Request) Retry(r int) *Request

Set how many times to retry if the request timedout or the server returned 5xx response.

func (*Request) Send

func (f *Request) Send() (*http.Response, error)

It will construct the client and the request, then send it

This function has to be called as the last thing, after setting the other properties

func (*Request) SetHeader

func (f *Request) SetHeader(key, value string) *Request

sets the header entries associated with key to the element value.

It replaces any existing values associated with key.

func (*Request) Timeout

func (f *Request) Timeout(t time.Duration) *Request

Timeout specifies a time limit for requests made by this Client. The timeout includes connection time, any redirects, and reading the response body. The timer remains running after Get, Head, Post, or Do return and will interrupt reading of the Response.Body.

A Timeout of zero means no timeout.

func (*Request) Url

func (f *Request) Url(url string) *Request

Set the request URL You probably want to use the methods [Post, Get, Patch, Delete, Put]

Jump to

Keyboard shortcuts

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