Skip to content

Instantly share code, notes, and snippets.

@thomaspoignant
Created February 21, 2024 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaspoignant/ea2bf2cdcd08aba029cb32d63b91d2b1 to your computer and use it in GitHub Desktop.
Save thomaspoignant/ea2bf2cdcd08aba029cb32d63b91d2b1 to your computer and use it in GitHub Desktop.
GO Feature Flag + OpenFeature example
import time
from gofeatureflag_python_provider.provider import GoFeatureFlagProvider
from gofeatureflag_python_provider.options import GoFeatureFlagOptions
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from gofeatureflag_python_provider.provider_status import ProviderStatus
def main():
goff_provider = GoFeatureFlagProvider(
options=GoFeatureFlagOptions(endpoint="http://localhost:1031/")
)
api.set_provider(goff_provider)
client = api.get_client(name="test-client")
evaluation_ctx = EvaluationContext(
targeting_key="d45e303a-38c2-11ed-a261-0242ac120002",
attributes={
"email": "john.doe@gofeatureflag.org",
"firstname": "john",
"lastname": "doe",
"anonymous": False,
"professional": True,
"rate": 3.14,
"age": 30,
"company_info": {"name": "my_company", "size": 120},
"labels": ["pro", "beta"],
},
)
while goff_provider.get_status() != ProviderStatus.READY:
time.sleep(0.5)
pass
admin_flag = client.get_boolean_details(
flag_key="bool_targeting_match",
default_value=False,
evaluation_context=evaluation_ctx,
)
print(admin_flag)
print("Hello, world!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment