Categorygithub.com/Planxnx/abtestx
modulepackage
0.9.1
Repository: https://github.com/planxnx/abtestx.git
Documentation: pkg.go.dev

# README

ABTestX

Go Reference Go Report Card Codacy Badge Code Analysis & Tests DeepSource license

A Simple A/B Testing library in Go

abtestx is a tool to help you run A/B tests for your golang applications with minimal effort and multiple strategies.

Requirements

  • go 1.18 or higher

Installation

go get github.com/Planxnx/abtestx

Strategies

  • Round Robin
  • Weighted Random
  • Random (soon)

Example

import (
	"fmt"
	"error"
	"github.com/Planxnx/abtestx"
)

func RoundRobin() {
	abtest := abtestx.NewRoundRobin([]abtestx.RoundRobinTest{
		{
			ID: "A",
			Callback: func() error {
				fmt.Println("execute A!")
				return nil
			},
		},
		{
			ID: "B",
			Callback: func() error {
				fmt.Println("execute B!")
				return nil
			},
		},
		{
			ID: "C",
			Callback: func() error {
				return errors.New("Error C")
			},
		},
	})

	err := abtest.Run() // execute A!
	err := abtest.Run() // execute B!
	err := abtest.Run() // err is not nil, got error "Error C"
	err := abtest.Run() // execute A!
	err := abtest.Run() // execute B!

}

func WeightedRandom() {
	abtest := abtestx.NewWeightedRandom([]abtestx.WeightedRandomTest{
		{
			ID:     "A",
			Weight: 0.8,
			Callback: func() error {
				fmt.Println("execute A!")
				return nil
			},
		},
		{
			ID:     "B",
			Weight: 0.2,
			Callback: func() error {
				fmt.Println("execute B!")
				return nil
			},
		},
	})

	// will execute A 80% of the time and B 20% of the time
	_ = abtest.Run() // execute A!
	_ = abtest.Run() // execute B!
	_ = abtest.Run() // execute A!
	_ = abtest.Run() // execute A!
	_ = abtest.Run() // execute A!
}

LICENSE

abtestx released under MIT license, refer LICENSE file.

# Packages

No description provided by the author

# Functions

NewRoundRobin creates a new ab-test with round-robin strategy instance.
NewWeightedRandom creates a new ab-test with weighted random strategy instance.

# Constants

default total weight.

# Structs

RoundRobin is a ab-test with round-robin strategy.
RoundRobinTest is a test data for round-robin strategy.
WeightedRandom is a ab-test with weighted random strategy.
WeightedRandomTest is a test data for weighted random strategy.

# Interfaces

Client is a a/b testing instance interface.