diff --git a/client.go b/client.go index 4988e3c..b049d2e 100644 --- a/client.go +++ b/client.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "strings" "sync/atomic" "time" @@ -54,6 +55,10 @@ func NewClient(apiKey string, options ...Option) *Client { c.client.SetLogger(c.log) if c.config.localEvaluation { + if !strings.HasPrefix(apiKey, "ser.") { + panic("In order to use local evaluation, please generate a server key in the environment settings page.") + } + go c.pollEnvironment(c.ctxLocalEval) } // Initialize analytics processor diff --git a/client_test.go b/client_test.go index 4607e53..68f5273 100644 --- a/client_test.go +++ b/client_test.go @@ -16,6 +16,13 @@ import ( "github.com/stretchr/testify/assert" ) +func TestClientErrorsIfLocalEvaluationWithNonServerSideKey(t *testing.T) { + // When, Then + assert.Panics(t, func() { + _ = flagsmith.NewClient("key", flagsmith.WithLocalEvaluation(context.Background())) + }) +} + func TestClientUpdatesEnvironmentOnStartForLocalEvaluation(t *testing.T) { // Given ctx := context.Background() diff --git a/fixtures/fixture.go b/fixtures/fixture.go index 6876f9d..805fa0f 100644 --- a/fixtures/fixture.go +++ b/fixtures/fixture.go @@ -6,7 +6,7 @@ import ( ) const BaseURL = "http://localhost:8000/api/v1/" -const EnvironmentAPIKey = "test_key" +const EnvironmentAPIKey = "ser.test_key" const Feature1Value = "some_value" const Feature1Name = "feature_1" const Feature1ID = 1