flagrc

package module
v0.0.0-...-30ecdf6 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

FLAGRC

Flagrc is a Flagr client for evaluator only. The main difference with https://github.com/checkr/goflagr is that,

flagrc act as a local evaluator allowing you to instead of calling flagr server for each request, It will resolve all your request locally. In order to do that flagrc load in memory, each EvalCacheRefreshInterval (by default 3) second (in backgound) the configuration from the main server, then It can resolve/evaluate all request locally.

flagrc uses all flagr function to act as a a real flagr Evaluator. flagrc uses all goflagr signature.

Example

    local := flagrc.NewClient(&goflagr.Configuration{
		BasePath: "http://localhost:18000/api/v1",
	})

    var ec interface{}
	ec = map[string]interface{}{"country": "ca"}
	result, _, err := local.PostEvaluation(ctx, goflagr.EvalContext{FlagKey: "HelloWorldFlag", EntityContext: &ec})

	if err == nil && result.VariantKey == "A" {
		fmt.Println("Hello Canada")
	}

Benchmark

Comparison between flagrc and goflagr :

$ go test -bench=.
goos: linux
goarch: amd64
pkg: github.com/tkanos/flagrc
BenchmarkGoFlagr_WithoutEntityID-8           100          19656778 ns/op
BenchmarkGoFlagr_WithEntityID-8              100          19679028 ns/op
BenchmarkFlagrc_WithoutEntityID-8         500000              3393 ns/op
BenchmarkFlagrc_WithEntityID-8            500000              3413 ns/op
PASS
ok      github.com/tkanos/flagrc        7.779s

Todo :

  • unit tests (how to mock client)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoServerAvailable error = errors.New("Server is not available")

Functions

This section is empty.

Types

type ClientOptions

type ClientOptions struct {
	EvalCacheRefreshInterval time.Duration
	LogrusLevel              string
	LogrusFormat             string
	EvalLoggingEnabled       bool
}

type Evaluator

type Evaluator interface {
	PostEvaluation(ctx context.Context, body goflagr.EvalContext) (goflagr.EvalResult, *http.Response, error)
	PostEvaluationBatch(ctx context.Context, body goflagr.EvaluationBatchRequest) (goflagr.EvaluationBatchResponse, *http.Response, error)
}

func NewClient

func NewClient(cfg *goflagr.Configuration, options ...func(t *ClientOptions)) (ev Evaluator)

Jump to

Keyboard shortcuts

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