Enhance the durability of your API by automatically recovering from connectivity failure
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore :octocat: Added .gitattributes & .gitignore files Oct 9, 2015
license Create license Oct 9, 2015


Image of insidethecpu

Go Fallback Package

Join the chat at https://gitter.im/daishisystems/month Build Status godoc

Package fallback enhances the durability of your API by automatically recovering from connectivity failure. It achieves this by providing an enhanced degree of redundancy to HTTP requests, introducing a Chain of Responsibility, consisting of a series of fallback HTTP requests designed to augment an initial HTTP request. Should the initial HTTP request fail, the next fallback HTTP request in the chain will execute.

Any number of fallback HTTP requests can be chained sequentially. Redundancy is achieved by executing each fallback HTTP request in a recursive manner until one of the requests succeeds, or all requests fail.



go get github.com/daishisystems/fallback

Sample Code

package main

import (

func main() {

	// BasicResponse represents the response issued from the first successful
	// HTTP request, if applicable.
	type BasicResponse struct {
		Text   string
		Detail string

	// BasicError represents the error issued from the last unsuccessful
	// HTTP request, if applicable.
	type BasicError struct {
		Code    int
		Message string

	type PostBody struct {
		Name   string
		Amount int

	basicResponse := &BasicResponse{}
	basicError := &BasicError{}

	postBody := PostBody{
		"Random", 100,

	passPath := "http://demo7227109.mockable.io/get-basic"
	failPath2 := "http://demo7227109.mockable.io/fail-basic"
	failPath1 := "http://demo7227109.mockable.io/fail-basic-post"

	connectionManager := fallback.ConnectionManager{}

	// This Connection will execute last, and will succeed.
	passBuilder := fallback.NewConnectionBuilder("PASS", "GET", passPath, true,
		nil, nil, &basicResponse, &basicError, nil)

	// This Connection will be the 2nd Connection to execute, and will fail.
	failBuilder2 := fallback.NewConnectionBuilder("FAIL2", "POST", failPath2,
		true, nil, nil, &basicResponse, &basicError, passBuilder.Connection)

	//This Connection will be the 1st Connection to execute, and will fail.
	failBuilder1 := fallback.NewConnectionBuilder("FAIL1", "POST", failPath1,
		true, postBody, nil, &basicResponse, &basicError,

	// Each Connection will be invoked in a recursive manner until a
	// Connection succeeds, or all Connections fail. Please refer to the Chain
	// of Responsibility design for more information.
	statusCode, err := failBuilder1.Connection.ExecuteHTTPRequest()
	if err != nil {

	fmt.Printf("HTTP status code: %d\n", statusCode)
	fmt.Printf("Text: %s\n", basicResponse.Text)
	fmt.Printf("Detail: %s", basicResponse.Detail)

Contact the Developer

Please reach out and contact me for questions, suggestions, or to just talk tech in general.