Documentation
¶
Overview ¶
Package flags is the Go client for the Hanzo native flags engine — cloud's /v1/flags (stateless Rust evaluator, per-org/project SQLite definitions, PostHog-compatible semantics).
c := flags.New("https://api.hanzo.ai", flags.WithToken(os.Getenv("HANZO_API_KEY")))
res, _ := c.Evaluate(ctx, flags.Context{DistinctID: "user-42",
PersonProperties: map[string]any{"plan": "pro"}})
if res.IsEnabled("new-nav") { ... }
switch res.Variant("checkout-exp") { case "treatment": ... }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EvaluateJSON ¶
EvaluateJSON is the wire-shaped entry point: a definitions array and an evaluation context, both JSON, in — the PostHog-shaped response out. Numbers keep their literal form through the decode so property comparisons see exactly what the caller sent.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client evaluates flags over POST {host}/v1/flags.
type ConditionGroup ¶
type ConditionGroup struct {
Properties []PropertyFilter `json:"properties,omitempty"`
// RolloutPercentage nil means 100%.
RolloutPercentage *float64 `json:"rollout_percentage,omitempty"`
// Variant pins a specific variant when this group matches (it must exist in
// Multivariate to take effect).
Variant *string `json:"variant,omitempty"`
}
ConditionGroup is one release condition: property filters plus a rollout.
type Context ¶
type Context struct {
DistinctID string `json:"distinct_id"`
PersonProperties map[string]any `json:"person_properties,omitempty"`
Groups map[string]GroupCtx `json:"groups,omitempty"` // group_type_index -> identity
}
Context is one evaluation identity.
type Def ¶
type Def struct {
Key string `json:"key"`
Active bool `json:"active"`
Deleted bool `json:"deleted"`
Filters Filters `json:"filters"`
// AggregationGroupTypeIndex, when set, aggregates the flag by a group type
// (its index) instead of by the person.
AggregationGroupTypeIndex *int `json:"aggregation_group_type_index,omitempty"`
}
Def is one flag definition.
func (*Def) UnmarshalJSON ¶
UnmarshalJSON decodes a definition, defaulting `active` to true when the key is absent — the wire contract a stored definition relies on.
type Filters ¶
type Filters struct {
Groups []ConditionGroup `json:"groups,omitempty"`
Multivariate *Multivariate `json:"multivariate,omitempty"`
// Payloads maps "true" -> the payload for a boolean match, or a variant key
// -> that variant's payload.
Payloads map[string]json.RawMessage `json:"payloads,omitempty"`
}
type Multivariate ¶
type Multivariate struct {
Variants []Variant `json:"variants,omitempty"`
}
type Operator ¶
type Operator string
Operator is the comparison a property filter applies.
const ( OpExact Operator = "exact" OpIsNot Operator = "is_not" OpIcontains Operator = "icontains" OpNotIcontains Operator = "not_icontains" OpRegex Operator = "regex" OpNotRegex Operator = "not_regex" OpGt Operator = "gt" OpLt Operator = "lt" OpGte Operator = "gte" OpLte Operator = "lte" OpSemverGt Operator = "semver_gt" OpSemverGte Operator = "semver_gte" OpSemverLt Operator = "semver_lt" OpSemverLte Operator = "semver_lte" OpSemverEq Operator = "semver_eq" OpSemverNeq Operator = "semver_neq" OpSemverTilde Operator = "semver_tilde" OpSemverCaret Operator = "semver_caret" OpSemverWildcard Operator = "semver_wildcard" OpIsSet Operator = "is_set" OpIsNotSet Operator = "is_not_set" OpIsDateExact Operator = "is_date_exact" OpIsDateAfter Operator = "is_date_after" OpIsDateBefore Operator = "is_date_before" OpIn Operator = "in" OpNotIn Operator = "not_in" OpFlagEvaluatesTo Operator = "flag_evaluates_to" )
func (*Operator) UnmarshalJSON ¶
UnmarshalJSON rejects unknown operators so a definition carrying one fails to parse rather than silently never matching.
type Option ¶
type Option func(*Client)
func WithHTTPClient ¶
WithHTTPClient overrides the HTTP client (default 5s timeout).
func WithProject ¶
WithProject scopes evaluation to a project (X-Project-Id).
type PropertyFilter ¶
type PropertyFilter struct {
Key string `json:"key"`
Value json.RawMessage `json:"value,omitempty"`
Operator *Operator `json:"operator,omitempty"`
Type PropertyType `json:"type"`
Negation *bool `json:"negation,omitempty"`
GroupTypeIndex *int `json:"group_type_index,omitempty"`
}
PropertyFilter is one property condition inside a condition group. Value is absent (nil) for the is_set / is_not_set operators, and for filters the API built without one.
type PropertyType ¶
type PropertyType string
PropertyType is which bag a property filter reads from.
const ( TypePerson PropertyType = "person" TypeCohort PropertyType = "cohort" TypeGroup PropertyType = "group" // TypeFlag compares against another flag's evaluation result. TypeFlag PropertyType = "flag" )
func (*PropertyType) UnmarshalJSON ¶
func (p *PropertyType) UnmarshalJSON(b []byte) error
UnmarshalJSON rejects unknown property types for the same reason as Operator.
type Result ¶
type Result struct {
FeatureFlags map[string]json.RawMessage `json:"featureFlags"`
FeatureFlagPayloads map[string]json.RawMessage `json:"featureFlagPayloads"`
ErrorsWhileComputingFlags bool `json:"errorsWhileComputingFlags"`
}
Result is the PostHog-shaped evaluation response.