ffcontext

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 0 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	// GetKey return the unique key for the context.
	GetKey() string
	// IsAnonymous return if the context is about an anonymous user or not.
	IsAnonymous() bool
	// GetCustom return all the custom properties added to the context.
	GetCustom() map[string]interface{}
	// AddCustomAttribute allows to add a custom attribute into the context.
	AddCustomAttribute(name string, value interface{})
}

type EvaluationContext

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

EvaluationContext contains specific attributes for your evaluation. Most of the time it is identifying a user browsing your site. The only mandatory property is the Key, which must a unique identifier. For authenticated users, this may be a username or e-mail address. For anonymous users, this could be an IP address or session ID.

EvaluationContext fields are immutable and can be accessed only via getter methods. To construct an EvaluationContext, use either a simple constructor (NewEvaluationContext) or the builder pattern with NewEvaluationContextBuilder.

func NewAnonymousEvaluationContext deprecated

func NewAnonymousEvaluationContext(key string) EvaluationContext

Deprecated: NewAnonymousEvaluationContext is here for compatibility reason. Please use NewEvaluationContext instead and add a custom attribute to know that it is an anonymous user.

ctx := NewEvaluationContext("my-key") ctx.AddCustomAttribute("anonymous", true)

func NewEvaluationContext

func NewEvaluationContext(key string) EvaluationContext

NewEvaluationContext creates a new evaluation context identified by the given key.

func (EvaluationContext) AddCustomAttribute

func (u EvaluationContext) AddCustomAttribute(name string, value interface{})

AddCustomAttribute allows to add a custom attribute into the user.

func (EvaluationContext) GetCustom

func (u EvaluationContext) GetCustom() map[string]interface{}

GetCustom return all the custom properties of a user.

func (EvaluationContext) GetKey

func (u EvaluationContext) GetKey() string

GetKey return the unique key for the user.

func (EvaluationContext) IsAnonymous

func (u EvaluationContext) IsAnonymous() bool

IsAnonymous return if the user is anonymous or not.

type EvaluationContextBuilder

type EvaluationContextBuilder interface {
	// Deprecated: Anonymous is to flag the context for an anonymous context or not.
	// This function is here for compatibility reason, please consider to use AddCustom("anonymous", true)
	// instead of using this function.
	Anonymous(bool) EvaluationContextBuilder

	AddCustom(string, interface{}) EvaluationContextBuilder
	Build() EvaluationContext
}

EvaluationContextBuilder is a builder to create an EvaluationContext.

func NewEvaluationContextBuilder

func NewEvaluationContextBuilder(key string) EvaluationContextBuilder

NewEvaluationContextBuilder constructs a new EvaluationContextBuilder, specifying the user key.

For authenticated users, the key may be a username or e-mail address. For anonymous users, this could be an IP address or session ID.

Jump to

Keyboard shortcuts

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