Skip to content

Go Client

Official Go client library for FigChain configuration management.

Installation

GitHub Release

go get github.com/figchain/go-client

Quick Start

package main

import (
    "fmt"
    "log"

    "github.com/figchain/go-client/pkg/client"
    "github.com/figchain/go-client/pkg/config"
    "github.com/figchain/go-client/pkg/evaluation"
)

// Define your configuration struct
type MyConfig struct {
    FeatureEnabled bool `avro:"feature_enabled"`
    MaxItems       int  `avro:"max_items"`
}

// Implement the AvroRecord interface
func (c *MyConfig) Schema() string {
    return `{
        "type": "record",
        "name": "MyConfig",
        "fields": [
            {"name": "feature_enabled", "type": "boolean"},
            {"name": "max_items", "type": "int"}
        ]
    }`
}

func main() {
    // Build the client
    c, err := client.New(
        config.WithBaseURL("https://api.figchain.io"),
        config.WithClientSecret("your-api-key"),
        config.WithEnvironmentID("your-environment-id"),
        config.WithNamespaces("default"),
    )
    if err != nil {
        log.Fatal(err)
    }
    defer c.Close()

    // Evaluate a configuration (for traffic split support)
    ctx := evaluation.NewEvaluationContext(map[string]string{
        "userId": "user123",
        "plan":   "premium",
    })

    // Retrieve and decode the configuration
    var cfg MyConfig
    if err := c.GetFig("your-fig-key", &cfg, ctx); err != nil {
        log.Printf("Error getting fig: %v", err)
        return
    }

    fmt.Printf("Feature Enabled: %v\n", cfg.FeatureEnabled)
}