posthog

package module
v0.0.0-...-a95c66f Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: MIT Imports: 4 Imported by: 0

README

Unofficial PostHog OpenFeature Provider for Go

This is an experimental unofficial PostHog OpenFeature provider for Go. It uses the official PostHog SDK under the hood.

Usage

import (
	"context"
	"fmt"

	phprovider "github.com/craigpastro/posthog-openfeature-provider-go"
	"github.com/open-feature/go-sdk/pkg/openfeature"
	"github.com/posthog/posthog-go"
)

func main() {
	phClient, err := posthog.NewWithConfig(
		"<POSTHOG_API_KEY>",
		posthog.Config{
			PersonalApiKey: "<PERSONAL_API_KEY>",
			Endpoint:       "https://app.posthog.com",
		},
	)
	if err != nil {
		panic(err)
	}
	defer phClient.Close()

	err = openfeature.SetProvider(phprovider.New(phClient))
	if err != nil {
		panic(err)
	}

	client := openfeature.NewClient("app")

	v2Enabled, err := client.BooleanValue(
		context.Background(),
		"v2_enabled",
		false,
		openfeature.NewEvaluationContext("my_distinct_id", nil),
	)
	if err != nil {
		panic(err)
	}

	if v2Enabled {
		fmt.Println("v2 is enabled")
	} else {
		fmt.Println("v2 is NOT enabled")
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

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

func New

func New(client posthog.Client) *Provider

New creates an OpenFeature provider backed by PostHog.

func (*Provider) BooleanEvaluation

func (p *Provider) BooleanEvaluation(
	ctx context.Context,
	flag string,
	defaultValue bool,
	evalCtx openfeature.FlattenedContext,
) openfeature.BoolResolutionDetail

func (*Provider) FloatEvaluation

func (p *Provider) FloatEvaluation(
	ctx context.Context,
	flag string,
	defaultValue float64,
	evalCtx openfeature.FlattenedContext,
) openfeature.FloatResolutionDetail

FloatEvaluation will always return the default value and PostHog does not have float evaluation.

func (*Provider) Hooks

func (p *Provider) Hooks() []openfeature.Hook

Hooks are not currently implemented so nil is returned.

func (*Provider) IntEvaluation

func (p *Provider) IntEvaluation(
	ctx context.Context,
	flag string,
	defaultValue int64,
	evalCtx openfeature.FlattenedContext,
) openfeature.IntResolutionDetail

IntEvaluation will always return the default value and PostHog does not have int evaluation.

func (*Provider) Metadata

func (p *Provider) Metadata() openfeature.Metadata

func (*Provider) ObjectEvaluation

func (p *Provider) ObjectEvaluation(
	ctx context.Context,
	flag string,
	defaultValue any,
	evalCtx openfeature.FlattenedContext,
) openfeature.InterfaceResolutionDetail

ObjectEvaluation will always return the default value and PostHog does not have object evaluation.

func (*Provider) StringEvaluation

func (p *Provider) StringEvaluation(
	ctx context.Context,
	flag string,
	defaultValue string,
	evalCtx openfeature.FlattenedContext,
) openfeature.StringResolutionDetail

StringEvaluation will always return the default value and PostHog does not have string evaluation.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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