Created
December 23, 2025 16:35
-
-
Save thomaspoignant/9704c7b90e2175b02f905402fe1c8970 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const { OpenFeature } = require("@openfeature/server-sdk"); | |
| const { | |
| GoFeatureFlagProvider, | |
| } = require("@openfeature/go-feature-flag-provider"); | |
| (async () => { | |
| try { | |
| // Initialize the GO Feature Flag provider | |
| const goFeatureFlagProvider = new GoFeatureFlagProvider({ | |
| endpoint: "http://localhost:1031/", // DNS of your instance of relay proxy | |
| apiKey: "team-b-api-key", | |
| }); | |
| // Get a client and set the provider | |
| const client = OpenFeature.getClient("my-app"); | |
| await OpenFeature.setProviderAndWait("my-app", goFeatureFlagProvider); | |
| // Set up user context (admin user for flag-only-for-admin) | |
| const userContext = { | |
| targetingKey: "admin-user-123", // user unique identifier (mandatory) | |
| admin: true, | |
| email: "admin@example.com", | |
| }; | |
| // Load the feature flag | |
| const flagKey = "flag-only-for-admin"; | |
| const flagDetails = await client.getBooleanDetails( | |
| flagKey, | |
| false, | |
| userContext | |
| ); | |
| // Display the result | |
| console.log("Flag Details:", JSON.stringify(flagDetails, null, 2)); | |
| console.log(`\nFlag "${flagKey}" value: ${flagDetails.value}`); | |
| console.log(`Reason: ${flagDetails.reason}`); | |
| // Clean up | |
| await OpenFeature.close(); | |
| } catch (error) { | |
| console.error("Error:", error.message); | |
| process.exit(1); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment