Created
February 21, 2024 17:55
-
-
Save thomaspoignant/ea2bf2cdcd08aba029cb32d63b91d2b1 to your computer and use it in GitHub Desktop.
GO Feature Flag + OpenFeature example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "[email protected]", | |
"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