reliable-request

module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: BSD-3-Clause

README

Reliablereq

A golang opinionated library to provide reliable request using hystrix-go, go-cache, and go-resiliency.

When you do a Get, it provides:

Usage

req := reliablereq.NewReliableRequest()
req.TTLCache = 1 * time.Second
req.EnableStaleCache = false
body, err := req.Get("http://example.com/list")

// passing authentication/authorization bearer token
req := reliablereq.NewReliableRequest()
req.Headers = map[string]string{"Authorization": "Bearer foobar"}
body, err := req.Get("http://example.com/list")

Opinionated defaults

// reliable request defaults
rr := ReliableRequest{
  EnableCache:        true,
  TTLCache:           1 * time.Minute,
  EnableStaleCache:   true,
  TTLStaleCache:      24 * time.Hour,
}
// hystrix
var defaultHystrixConfiguration = hystrix.CommandConfig{
  Timeout:                800 + 100, // the defaultTimeout http client + a small gap
  MaxConcurrentRequests:  100,
  ErrorPercentThreshold:  50,
  RequestVolumeThreshold: 3,
  SleepWindow:            5000,
}
// http client
client := &http.Client{
  Transport: &http.Transport{
    DialContext: (&net.Dialer{
      Timeout:   800 * time.Millisecond,
      KeepAlive: 30 * time.Second,
    }).DialContext,
    MaxIdleConns:        100,
    MaxIdleConnsPerHost: 100,
    TLSHandshakeTimeout: 800 * time.Millisecond,
  },
  Timeout: 800 * time.Millisecond,
}

Future

  • provide a proxy to setup hystrix
  • add more examples, like token header requests and more
  • discuss the adopted defaults
  • discuss whether async hystrix is better (Go instead of Do)
  • understand and test the simultaneous client req hystrix config to see its implications
  • add go api documentation
  • add retry logic (by go-resiliency)
  • add hooks (callbacks) to provides means for metrics gathering
  • add more HTTP verbs?
  • add load stress

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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