Initialization

To create a Wingify Client instance, you need to initialize the Wingify FE Go SDK. This client instance serves as the core interface for conducting Feature Experimentation(A/B and personalization) within your application.

Usage

package main

import (
    "fmt"
    "log"

    wingify "github.com/wingify/wingify-fme-go-sdk"
)

func main() {
    // Initialize Wingify SDK with your account details
    options := map[string]interface{}{
        "sdkKey":    "32-alpha-numeric-sdk-key", // Replace with your SDK key
        "accountId": "123456",                   // Replace with your account ID
    }

    // Initialize Wingify wingifyClient
    wingifyClient, err := wingify.Init(options)
    if err != nil {
        log.Fatalf("Failed to initialize Wingify client: %v", err)
    }
}

The Init function is called with the sdkKeyand accountId. It initializes and returns a Wingify Client Object wingifyClient.
This client object allows you to run experiments, track events, and enable/disable feature flags.

Parameter Definitions

ParameterTypeDescription
accountId
Required
IntegerYour Wingify application's Account ID.
sdkKey
Required
StringA unique environment key is provided to you inside the Websites & Apps section in the Wingify application, under Default Project.
pollInterval
Optional
IntegerTime (in milliseconds) at which Wingify should check with the server for any updates to the feature flag or rules in the Wingify Dashboard. Useful to keep your Wingify Client instance up-to-date with any changes made in the Wingify Application. For more details, please check -Polling
logger
Optional
map[string]interfaceAn optional logger object that defines the logging behavior. For more details, please check - Logger
storage
Optional
ObjectStorage Service, if required, can be implemented using this parameter. For more details, please check - Storage Service
gatewayService
Optional
map[string]interfaceIf using the FE Gateway Service, this object will specify the location and port of where the gateway service is deployed on your servers.
integrations
Optional
map[string]interfaceA callback function that receives data which can be pushed to any external tool that you need to integrate with. For more details, please check - Integrations
retryConfig
Optional
map[string]interfaceConfiguration for network request retry behavior and exponential backoff strategy. For more details, please check - Retry Config
proxyUrl
Optional
StringCustom proxy URL for redirecting all SDK network requests through a proxy server. Please check - ProxyUrl

Poll Interval (Keeping Wingify client up-to-date)

When you initialize the wingifyClient on your server, it pulls the latest configurations you've done in the Wingify application.
If/when you make any changes to the feature flags or rules within Wingify after the wingifyClient has been initialized in your server, there needs to be some way to update your wingifyClient with the latest settings from. This can be done via polling.

The poll interval is an optional parameter that allows the SDK to automatically fetch and update settings from the Wingify server at specified intervals. Setting this parameter ensures your application always uses the latest configuration.

options := map[string]interface{}{
    "sdkKey":       "32-alpha-numeric-sdk-key",
    "accountId":    "123456",
    "pollInterval": 60000, // Set the poll interval to 60 seconds
}

wingifyClient, err := wingify.Init(options)

Logger

Wingify by default logs all ERROR level messages to your server console. To gain more control over Wingify's logging behavior, you can use the logger parameter in the init configuration.

options := map[string]interface{}{
    "sdkKey":    "32-alpha-numeric-sdk-key",
    "accountId": "123456",
    "logger": map[string]interface{}{
        "level": "DEBUG",
    },
}

wingifyClient, err := wingify.Init(options)

Please click here for more advanced logger options.

Storage

By default, the SDK operates in stateless mode, evaluating flags on each getFlag call. To improve performance and consistency, you can use a custom storage mechanism to cache decisions, ensuring stable user experiences and reducing application load.

// Use in initialization
options := map[string]interface{}{
    "sdkKey":    "32-alpha-numeric-sdk-key",
    "accountId": "123456",
    "storage":   customStorage,
}

wingifyClient, err := wingify.Init(options)

Please click here to learn more about storage implementation.

Gateway Service

The Wingify FE Gateway Service enhances Feature Experimentation (FE) SDKs by enabling pre-segmentation based on user location and user agent. It ensures minimal latency and improved security. The service can be customized via the gatewayService parameter during initialization.

options := map[string]interface{}{
    "sdkKey":    "32-alpha-numeric-sdk-key",
    "accountId": "123456",
    "gatewayService": map[string]interface{}{
        "url": "http://custom.gateway.com",
    },
}

wingifyClient, err := wingify.Init(options)

Please click here to learn more about the Wingify Gateway service.

Integrations

Wingify FE SDKs provide seamless integration with third-party tools like analytics platforms, monitoring services, customer data platforms (CDPs), and messaging systems. This is achieved through a simple yet powerful callback mechanism that receives Wingify-specific properties and can forward them to any third-party tool of your choice.

options := map[string]interface{}{
    "sdkKey":       "32-alpha-numeric-sdk-key",
    "accountId":    "123456",
    "integrations": map[string]interface{}{
        "Callback": func(properties map[string]interface{}) {
            // implement your custom logic here
            fmt.Printf("Integration callback called with properties: %+v\n", properties)
        },
    },
}

wingifyClient, err := wingify.Init(options)

Please click here to learn more about Integrations,.

Initialization with Explicit Settings

The SDK provides the ability to reduce initialization time by allowing users to explicitly pass in settings instead of fetching them automatically. This can be especially useful in environments where you need to optimize for faster setup or if you already have the necessary settings retrieved from a remote server.
Please refer to this document for more information on retrieving settings.

var localSettings = '{
    "accountId": 123456,
    "sdkKey": '32-alpha-numeric-sdk-key',
    "features": {
        // features json here
    },
    "campaigns": {
        // campaigns json here
    },
    "version": 1,
}'

options := map[string]interface{}{
    "sdkKey":       "32-alpha-numeric-sdk-key",
    "accountId":    "123456",
    "settings": localSettings,
}

wingifyClient, err := wingify.Init(options)

Retry Config

The retryConfig parameter allows you to customize the retry behavior for network requests. This is particularly useful for applications that need to handle network failures gracefully with exponential backoff strategies.

options := map[string]interface{}{
    "sdkKey":    "32-alpha-numeric-sdk-key",
    "accountId": "123456",
    "retryConfig": map[string]interface{}{
        "shouldRetry":       true,  // Enable retries
        "maxRetries":        5,     // Retry up to 5 times
        "initialDelay":      3,     // Wait 3 seconds before first retry
        "backoffMultiplier": 2,     // Double the delay for each subsequent retry
    },
}

wingifyClient, err := wingify.Init(options)

Please click here to learn more about retry configuration.

ProxyUrl

The proxyUrl parameter allows you to redirect all SDK network calls through a custom proxy server. This feature enables you to route all SDK network requests (settings, tracking, etc.) through your own proxy server, providing better control over network traffic and security.

How to Use Proxy URL
The proxy URL can be configured by passing the proxyUrl parameter in the init configuration.

options := map[string]interface{}{
    "sdkKey":    "32-alpha-numeric-sdk-key", // Replace with your SDK key
    "accountId": "123456",                   // Replace with your account ID
    "proxyUrl": "https://custom.proxy.com",  // Replace with your custom proxy url
}

// Initialize Wingify instance
wingifyClient, err := wingify.Init(options)

Please click here to learn more about Proxy URL.



What’s Next

Did this page help you?