revaboxy

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const DefaultName = "default"

DefaultName is the name of the default version The version with this name will take up the rest of the probability if any remain when adding all probabilities together

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Printf(string, ...interface{})
}

Logger is the logger interface used with revaboxy

type Revaboxy

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

Revaboxy creates an A/B test between different urls. It does also save which test i run on the client through cookies and serve the same version on subsequent requests The revaboxy handler should be created with New

func New

func New(vv []Version, settingChangers ...Setting) (*Revaboxy, error)

New creates a revaboxy client. Versions required but, any number of additional settings may be provided

Example
package main

import (
	"log"
	"net/http"
	"net/url"

	"github.com/lindell/revaboxy/pkg/revaboxy"
)

func main() {
	defaultURL, _ := url.Parse("http://defaulturl")
	greenBackgroundURL, _ := url.Parse("http://greenbackgroundurl")

	rp, err := revaboxy.New([]revaboxy.Version{
		{
			revaboxy.DefaultName,
			defaultURL,
			0.7,
		},
		{
			"green-background",
			greenBackgroundURL,
			0.3,
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	log.Fatal(http.ListenAndServe(":8080", rp))
}
Output:

func (*Revaboxy) ServeHTTP

func (revaboxy *Revaboxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Setting

type Setting func(s *settings)

Setting changes the revaboxy settings

func WithCookieExpiry

func WithCookieExpiry(expiry time.Duration) Setting

WithCookieExpiry sets the expiry time of the client cookie, default is 3 days

func WithCookieName

func WithCookieName(cookieName string) Setting

WithCookieName sets the name of the cookie that where the selected version is stored If the value is not set with this setting, it will default to the default, "revaboxy-name"

func WithHeaderName

func WithHeaderName(headerName string) Setting

WithHeaderName sets the name of the header that is set for the downsteam service to use The header will contain the name of the version used If the value is not set with this setting, it will default to the default, "revaboxy-name"

func WithLogger

func WithLogger(l Logger) Setting

WithLogger sets the logger to be used

func WithTransport

func WithTransport(rt http.RoundTripper) Setting

WithTransport sets the http transport to be used

type Version

type Version struct {
	// The name of the a/b testing version
	Name string
	// The URL to the root of the target
	URL *url.URL
	// The probability from 0-1 of this version being used
	Probability float64
}

Version is one of the versions used in the A/B/C... test

Jump to

Keyboard shortcuts

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