func RegisterEndpoint(w http.ResponseWriter, r *http.Request) {
	var httpMethod string
	a := API{}
	err := json.NewDecoder(r.Body).Decode(&a)
	if err != nil {
		RenderJSON(w, http.StatusBadRequest, NewResponse(err.Error()))
		return
	}
	if httpMethod, err = getAllowedMethod(a.HTTPMethod); err != nil {
		RenderJSON(w, http.StatusBadRequest, NewResponse(err.Error()))
		return
	}
	eKey, rcpKey := getCacheKeys(a.Endpoint, httpMethod)
	if _, ok := store.Get(eKey); ok {
		RenderJSON(w, http.StatusOK, NewResponse("endpoint already taken"))
		return
	}
	obj := NewObject()
	err = obj.Load(a.Payload)
	if err != nil {
		RenderJSON(w, http.StatusInternalServerError, NewResponse(err.Error()))
		return
	}
	store.Set(eKey, obj, maxItemTime)
	store.Set(rcpKey, a.ResponseCodeProbabilities, maxItemTime)
	RenderJSON(w, http.StatusOK, NewResponse("cool"))
}
RegisterEndpoint receives API objects and registers them. The payload from the request is
transformed into a self aware Value that is capable of faking its own attribute.
package apidemic
import (
	"encoding/json"
	"errors"
	"fmt"
	"math/rand"
	"net/http"
	"time"
	"github.com/gorilla/mux"
	"github.com/pmylund/go-cache"
)
const Version = "0.4"
var maxItemTime = cache.DefaultExpiration
var store = func() *cache.Cache {
	c := cache.New(5*time.Minute, 30*time.Second)
	return c
}()
var allowedHttpMethods = []string{"OPTIONS", "GET", "POST", "PUT", "DELETE", "HEAD"}
type API struct {
	Endpoint                  string                 `json:"endpoint"`
	HTTPMethod                string                 `json:"http_method"`
	ResponseCodeProbabilities map[int]int            `json:"response_code_probabilities"`
	Payload                   map[string]interface{} `json:"payload"`
}
func Home(w http.ResponseWriter, r *http.Request) {
	details := make(map[string]interface{})
	details["app_name"] = "ApiDemic"
	details["version"] = Version
	details["details"] = "Fake JSON API response"
	RenderJSON(w, http.StatusOK, details)
	return
}
func FindResponseCode(responseCodeProbabilities map[int]int, method string) int {
	sum := 0
	r := rand.Intn(100)
	for code, probability := range responseCodeProbabilities {
		if probability+sum > r {
			return code
		}
		sum = sum + probability
	}
	if method == "POST" {
		return http.StatusCreated
	}
	return http.StatusOK
}
func RenderJSON(w http.ResponseWriter, code int, value interface{}) {
	if code >= 400 || code == http.StatusNoContent {
		http.Error(w, "", code)
		return
	}
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(code)
	err := json.NewEncoder(w).Encode(value)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}