Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/disable-geo-ip-in-config' into d…
Browse files Browse the repository at this point in the history
…isable-geo-ip-in-config
  • Loading branch information
theartofdevel committed May 4, 2024
2 parents a30c1ea + 2de21a9 commit 2181be8
Show file tree
Hide file tree
Showing 13 changed files with 819 additions and 113 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.15
- name: Set up Go 1.18
uses: actions/setup-go@v1
with:
go-version: 1.15
go-version: 1.18

- name: Check out source code
uses: actions/checkout@v1
Expand All @@ -20,4 +20,4 @@ jobs:
run: go build .

- name: Test
run: go test -v .
run: go test -timeout 30s -v .
16 changes: 15 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ type Config struct {
// timer triggers.
Interval time.Duration

// Interval at which to fetch new feature flags, 5min by default
// Interval at which to fetch new feature flag definitions, 5min by default
DefaultFeatureFlagsPollingInterval time.Duration

// Timeout for fetching feature flags, 3 seconds by default
FeatureFlagRequestTimeout time.Duration

// Calculate when feature flag definitions should be polled next. Setting this property
// will override DefaultFeatureFlagsPollingInterval.
NextFeatureFlagsPollingTick func() time.Duration

// The HTTP transport used by the client, this allows an application to
// redefine how requests are being sent at the HTTP level (for example,
// to change the connection pooling policy).
Expand Down Expand Up @@ -98,6 +105,9 @@ const DefaultInterval = 5 * time.Second
// Specifies the default interval at which to fetch new feature flags
const DefaultFeatureFlagsPollingInterval = 5 * time.Minute

// Specifies the default timeout for fetching feature flags
const DefaultFeatureFlagRequestTimeout = 3 * time.Second

// This constant sets the default batch size used by client instances if none
// was explicitly set.
const DefaultBatchSize = 250
Expand Down Expand Up @@ -147,6 +157,10 @@ func makeConfig(c Config) Config {
c.DefaultFeatureFlagsPollingInterval = DefaultFeatureFlagsPollingInterval
}

if c.FeatureFlagRequestTimeout == 0 {
c.FeatureFlagRequestTimeout = DefaultFeatureFlagRequestTimeout
}

if c.Transport == nil {
c.Transport = http.DefaultTransport
}
Expand Down
3 changes: 2 additions & 1 deletion examples/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"fmt"
"github.com/posthog/posthog-go"
"time"

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

func TestCapture() {
Expand Down
23 changes: 14 additions & 9 deletions examples/featureflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import (
)

func TestIsFeatureEnabled() {
client, _ := posthog.NewWithConfig("phc_X8B6bhR1QgQKP1WdpFLN82LxLxgZ7WPXDgJyRyvIpib", posthog.Config{
Interval: 30 * time.Second,
BatchSize: 100,
Verbose: true,
PersonalApiKey: "phx_vXZ7AOnFjDrCxfWLyo9V6P0SWLLfXT2d5euy3U0nRGk",
client, _ := posthog.NewWithConfig("phc_36WfBWNJEQcYotMZ7Ui7EWzqKLbIo2LWJFG5fIg1EER", posthog.Config{
Interval: 30 * time.Second,
BatchSize: 100,
Verbose: true,
PersonalApiKey: "phx_n79cT52OfsxAWDhZs9j3w67aRoBCZ7l5ksRRKmAi5nr",
Endpoint: "http://localhost:8000",
DefaultFeatureFlagsPollingInterval: 5 * time.Second,
FeatureFlagRequestTimeout: 3 * time.Second,
})
defer client.Close()

Expand All @@ -22,38 +25,40 @@ func TestIsFeatureEnabled() {
DistinctId: "hello",
})

fmt.Println("boolResult:", boolResult)

if boolErr != nil || boolResult == nil {
fmt.Println("error:", boolErr)
return
}

// Simple flag
simpleResult, simpleErr := client.GetFeatureFlag(posthog.FeatureFlagPayload{
Key: "simple-test",
DistinctId: "hello",
})

fmt.Println("simpleResult:", simpleResult)
if simpleErr != nil || simpleResult == false {
fmt.Println("error:", simpleErr)
return
}

// Multivariate flag
variantResult, variantErr := client.GetFeatureFlag(posthog.FeatureFlagPayload{
Key: "multivariate-test",
DistinctId: "hello",
})
fmt.Println("variantResult:", variantResult)
if variantErr != nil || variantResult != "variant-value" {
fmt.Println("error:", variantErr)
return
}

// Multivariate + simple flag
variantResult, variantErr = client.GetFeatureFlag(posthog.FeatureFlagPayload{
Key: "multivariate-simple-test",
DistinctId: "hello",
})
fmt.Println("variantResult:", variantResult)
if variantErr != nil || variantResult == true {
fmt.Println("error:", variantErr)
return
}
}
Loading

0 comments on commit 2181be8

Please sign in to comment.