Skip to main content

Prerequisites

  • Go 1.21 or later
  • A Flagmint account and SDK API key (starts with ff_)
Management API coming soon. Programmatic flag creation via API is not yet available. Create and manage flags in the Flagmint dashboard.

Installation

go get github.com/flagmint/flagmint-go

Your First Flag

package main

import (
    "context"
    "fmt"
    "log"
    "time"

    flagmint "github.com/flagmint/flagmint-go"
)

func main() {
    client, err := flagmint.NewClient("fm_sdk_your_api_key",
        flagmint.WithContext(flagmint.EvaluationContext{
            Kind: "user",
            Key:  "user-123",
            Attributes: map[string]any{
                "country": "DE",
                "plan":    "pro",
            },
        }),
    )
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    // Wait until flags are available (at most 5 seconds).
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()

    if err := client.Ready(ctx); err != nil {
        log.Fatal("failed to initialise:", err)
    }

    if client.BoolFlag("dark-mode", false) {
        fmt.Println("Dark mode is enabled!")
    }
}

What’s happening

StepDescription
NewClientCreates the client and starts connecting asynchronously
WithContextSets the evaluation context (who is requesting the flag)
ReadyBlocks until flags are fetched from the server or the timeout expires
BoolFlagReturns the flag value, or false (the fallback) if not set

Subscribing to Flag Changes

Register a callback to react whenever flags are updated:
unsub := client.Subscribe(func(flags flagmint.FeatureFlags) {
    fmt.Println("Flags updated:", flags.Len(), "flags")
})
defer unsub() // remove the subscription when done
The callback fires immediately with the current flag state, then again on every update.

Next Steps

Configuration

All With* options, endpoint overrides, and logger setup

Local Evaluation

Evaluate flags in-process — no network round-trip

Transport

WebSocket vs HTTP, reconnection, and fallback behaviour

Caching

Built-in cache, TTL, and custom adapters