Introducing a new way to review your PRs.

Read the announcement

thomaspoignant / go-feature-flag

GO Feature Flag is a simple, complete and lightweight self-hosted cloud native feature flag solution 100% Open Source — built on OpenFeature 🎛️

View on GitHub

18 documents · Updated Nov 23, 2026

docs / flag-retriever-integrations

Flag retriever integrations

Flag retrievers connect the flag manager to external sources such as files, web services, cloud objects, databases, Redis, and Kubernetes ConfigMaps. Each integration turns its source data into flag configuration bytes so the manager can parse, merge, validate, and publish it without changing the evaluation path. See SDK configuration and flag retrieval for source ordering, refresh, fallback, and cache publication, and Configuration schema and models for the configuration model.

Shared retriever contract

Source adapter contract

A retriever is a source adapter that implements Retrieve, accepts a context, and returns the complete flag configuration as bytes or an error. The manager does not need to know how the source stores the data. This boundary lets file and network sources use the same load and refresh flow.

Retrievers that need a client or connection can also expose initialization, status, and shutdown behavior. The manager uses READY, NOT_READY, and ERROR to decide whether a retriever can take part in a load. Some lifecycle-aware retrievers can receive the configured flagset so a source can select one named group of flags.

References: retriever/retriever.go• L10-52 retriever/manager.go• L109-161

Data format contract

The returned bytes must describe valid flag definitions in a supported format. Most source adapters return JSON because they build the flag document from structured source records. File and HTTP sources return the source response as-is, so their format follows the configured file format unless the retriever provides a format hint.

The manager uses OutputFormat when a retriever declares one. This allows database and cache integrations to return JSON even when the global parser is set to YAML or TOML.

References: retriever/retriever.go• L16-25 retriever/manager.go• L317-366 retriever/…/retriever.go• L142-145

Integration lifecycle

The SDK creates each configured retriever through its kind and then uses the same manager flow for every source. A lifecycle-aware integration opens its client during setup, reads during refresh, and releases its client during shutdown. A simple file retriever needs no setup because it reads only when the manager asks for data.

The following diagram shows the common path from source selection to flag evaluation.

flowchart LR
    A[Retriever configuration] --> B[Source adapter]
    B --> C[Retrieve flag bytes]
    C --> D[Format selection]
    D --> E[Parse and validate]
    E --> F[Merge into flag cache]
    F --> G[Flag evaluation]

References: cmdhelpers/…/retriever_init.go• L27-57 retriever/manager.go• L295-366 internal/…/cache_manager.go• L56-101

File and HTTP integrations

Local file retriever

The file retriever reads one local flat file on each retrieval. Its path is the only source location that it needs, so it is suited to flags mounted into the same process or stored beside the application.

The file contents pass to the normal parser. The file therefore remains the source of the flag format and must match the SDK's selected format.

References: retriever/…/retriever.go• L8-19 cmdhelpers/…/retriever_conf.go• L91-93

HTTP retriever

The HTTP retriever reads flag configuration from an endpoint. It supports a request method, body, headers, timeout, and optional mutual TLS files so the endpoint can use normal request or client-certificate access controls.

The retriever treats an HTTP response with a status above 399 as a failed retrieval and returns the response body for successful responses. The request uses the refresh context, so cancellation can stop an in-flight source read.

References: retriever/…/retriever.go• L19-47 retriever/…/retriever.go• L81-100 retriever/…/http.go• L13-52

Git-provider integrations

Repository file retrievers

The GitHub, GitLab, and Bitbucket retrievers read one file from a repository branch. They share the same source shape: repository identifier, file path, branch, optional provider token, optional provider base URL, and a request timeout.

The default branch is main. The default service endpoint is the public provider endpoint, while BaseURL supports GitHub Enterprise, GitLab installations, or Bitbucket-compatible deployments. The providers reject missing repository or path values before making a request.

The GitLab adapter treats the repository slug and file path as URL path values, so nested paths and characters such as spaces or plus signs identify the intended repository file.

GitHub also supports GitHub App authentication for installations that need managed access to private repositories. The app uses an App ID, an installation ID, and an RSA private key supplied as text or a file. These fields cannot be combined with a personal access token. The retriever obtains and caches a short-lived installation token, refreshes it before expiry, and retries one contents request after an unauthorized response.

References: retriever/…/retriever.go• L27-47 retriever/…/retriever.go• L72-112 retriever/…/retriever.go• L114-172 retriever/…/retriever.go• L190-276 retriever/…/jwt.go• L14-49 retriever/…/retriever.go• L15-40 retriever/…/retriever.go• L42-90 retriever/…/retriever_test.go• L177-262 retriever/…/retriever.go• L16-27 cmdhelpers/…/retriever_init.go• L61-113

Provider access and limits

Provider tokens are optional for public content and provide access to protected repositories when present. GitHub access can use either a personal access token or a complete GitHub App configuration. The GitHub and Bitbucket adapters track rate-limit response data and stop calls while the provider reports that the limit is exhausted. GitLab delegates its request to the shared HTTP behavior, including response and timeout handling.

A provider response is still only flag input. The returned file must use a format that the manager can parse, and a provider error leaves the current loaded flag state unchanged during a later refresh.

References: retriever/…/retriever.go• L53-80 retriever/…/retriever.go• L98-112 retriever/…/retriever.go• L316-323 retriever/…/retriever_app_test.go• L179-234 retriever/…/retriever.go• L48-91 retriever/…/retriever.go• L42-90

Cloud-storage integrations

Object storage retrievers

The S3, Google Cloud Storage, and Azure Blob Storage retrievers read flag data from cloud objects. S3 supports both one named object and a folder mode that selects several objects by key prefix, file-name pattern, and recursive search. The selected S3 files are merged into one flag set before the manager receives the result.

Their source identity is expressed as:

IntegrationSource identityAccess model
S3Bucket and item key, or a prefix with optional pattern and recursive searchAWS SDK configuration and default AWS credentials unless supplied through the SDK configuration.
Google Cloud StorageBucket and object nameGoogle Cloud client options and the process credential environment.
Azure Blob StorageAccount name, container, and object nameAccount key or default Azure credentials.

References: retriever/…/retriever.go• L20-64 retriever/…/store.go• L11-45 retriever/…/retriever.go• L14-34 retriever/…/retriever.go• L14-36 cmdhelpers/…/retriever_init.go• L120-147 cmdhelpers/…/retriever_init.go• L175-182

Object freshness

S3 and Azure use an initialized cloud client before they read the object. In S3 folder mode, the retriever lists matching objects and uses each object's ETag to avoid downloading files that did not change. It drops files that no longer appear and rebuilds the merged flag set from the current selection. S3 listing walks all result pages and uses a delimiter when recursive search is off, so non-recursive mode returns only direct children of the selected prefix.

The S3 folder mode accepts JSON, YAML, or TOML files, but all selected files must use the same format. Unsupported file types are skipped. Duplicate flag names within the selected files are an error. An empty selection produces an empty flag set. Item mode returns the named object as-is and does not use the folder cache.

The S3 folder selection normalizes leading and trailing slashes in its prefix. An empty prefix or / means the bucket root. A pattern matches the file name only and cannot contain /; recursive search controls whether nested keys are included.

The Google Cloud Storage adapter checks object metadata and can return its local copy when the remote object hash has not changed. Cloud access errors, missing containers or buckets, missing objects, and invalid selected content surface as retrieval errors. The manager then keeps the last complete flag cache instead of publishing partial source data.

References: retriever/…/retriever.go• L82-220 retriever/…/store.go• L19-45 retriever/…/retriever_test.go• L72-300 retriever/…/retriever_test.go• L435-582 internal/…/loader.go• L74-193 internal/…/loader.go• L204-357 retriever/…/retriever.go• L40-88 retriever/…/retriever.go• L38-128 retriever/manager.go• L317-354

Database integrations

PostgreSQL retriever

The PostgreSQL retriever reads flag rows from a table and builds one JSON flag document from them. The required source identity is a database URI and table name. A column map can adapt the source to different names for the flag name, flagset, and configuration fields.

When a non-default flagset is configured, the retriever limits its query to that flagset. It returns an empty JSON object when no matching rows exist, which is valid source data rather than a connection failure. PostgreSQL pools are shared by URI and released by reference count, so retrievers using the same URI reuse one pool while the last shutdown closes it.

References: retriever/…/retriever.go• L16-32 retriever/…/retriever.go• L78-145 retriever/…/postgres.go• L10-63 retriever/…/postgres_test.go• L16-90 cmdhelpers/…/retriever_conf.go• L46-59

MongoDB retriever

The MongoDB retriever reads documents from one database collection and uses each document's string flag field as the flag key. The remaining document fields become that flag's definition, and the adapter returns the result as JSON.

The URI, database, and collection identify the source. The retriever must complete initialization before a read, and it reports a connection error when setup fails. Documents without a string flag field are ignored and reported through the retriever logger, so source quality affects which definitions reach the cache.

References: retriever/…/retriever.go• L14-27 retriever/…/retriever.go• L29-65 retriever/…/retriever.go• L67-110 retriever/…/retriever_unit_test.go• L11-28 retriever/…/retriever_test.go• L24-132 cmdhelpers/…/retriever_conf.go• L159-169

Redis integration

Redis flag retriever

The Redis retriever treats matching Redis keys as individual flags. It scans keys that start with the configured prefix, removes that prefix from each flag name, parses each value as JSON, and returns one JSON object for the manager.

Redis connection options define access to the server. Initialization checks the connection before the retriever becomes ready, and shutdown closes the client and returns it to a not-ready state. The prefix is optional; when it is empty, all scanned keys are candidates. A malformed value or failed key read fails the retrieval rather than publishing a partly built flag document.

References: retriever/…/retriever.go• L15-27 retriever/…/retriever.go• L29-72 retriever/…/retriever.go• L74-112 retriever/…/retriever_unit_test.go• L11-28 retriever/…/retriever_test.go• L20-238 cmdhelpers/…/retriever_conf.go• L61-68

Kubernetes integration

ConfigMap retriever

The Kubernetes retriever reads one key from one ConfigMap in one namespace. The value stored under that key is the complete flag configuration, so the ConfigMap can hold YAML, JSON, or TOML according to the SDK parser choice.

The integration uses the pod's in-cluster Kubernetes access during configuration. Its required source identity is the namespace, ConfigMap name, and data key. A missing ConfigMap or key fails the retrieval.

References: retriever/…/retriever.go• L16-23 retriever/…/retriever.go• L25-56 cmdhelpers/…/retriever_init.go• L149-160 cmdhelpers/…/retriever_conf.go• L146-156

Retriever selection

Configuration kinds

The retriever configuration names the source with a kind value. The initializer maps that value to one source adapter and applies shared defaults such as a ten-second timeout, the GET method, and the main branch where those defaults apply.

KindSourceRequired source settings
fileLocal filepath
httpHTTP endpointurl
githubGitHub repository filerepositorySlug, path
gitlabGitLab repository filerepositorySlug, path
bitbucketBitbucket repository filerepositorySlug, path
s3Amazon S3 object or selected object folderbucket; item for one object or folder selection fields for folder mode
googleStorageGoogle Cloud Storage objectbucket, object
azureBlobStorageAzure Blob Storage objectaccountName, container, object
postgresqlPostgreSQL tableuri, table
mongodbMongoDB collectionuri, database, collection
redisRedis keysredisOptions.addr
configmapKubernetes ConfigMap entrynamespace, configmap, key

References: cmdhelpers/…/retriever_conf.go• L21-68 cmdhelpers/…/retriever_conf.go• L70-109 cmdhelpers/…/retriever_conf.go• L195-221 cmdhelpers/…/retriever_init.go• L30-57 retriever/…/retriever.go• L31-53

Layered sources

The SDK can use more than one retriever. The manager reads configured sources in parallel, then combines their definitions in configuration order. If the same flag appears more than once, the later source wins, so source order is a deliberate override rule rather than a display detail.

References: config.go• L56-65 retriever/manager.go• L295-354

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep every accepted kind in step across configuration validation, factory selection, and the supported-integration table.
  • Keep each factory's field mapping aligned with the retriever's required source identity. A renamed field can pass config decoding but create an unusable adapter.
  • Recheck whether structured integrations still return JSON and keep their OutputFormat hint aligned with that output.
  • Preserve provider token and base-URL handling when changing Git-provider request paths or authentication.
  • Keep GitHub personal-token and App authentication mutually exclusive, and keep App ID, installation ID, and private-key validation aligned with token minting.
  • Preserve GitHub App token caching, expiry refresh, unauthorized retry, and private-key source precedence when changing GitHub authentication.
  • Recheck cloud credential selection and object identity together when changing storage adapters.
  • Keep database row or document shape aligned with the JSON shape expected by flag parsing.
  • Preserve Redis prefix semantics because the prefix changes the final flag key.
  • Recheck ConfigMap value and key handling when changing Kubernetes configuration or in-cluster setup.
  • Preserve PostgreSQL pool sharing and release behavior when changing connection setup or shutdown paths.
  • Keep S3 item and folder modes mutually exclusive, and keep folder selection rules aligned with prefix normalization, pattern matching, recursion, and supported file formats.
  • Preserve the S3 listing boundary: folder mode must return all pages, honor direct-child versus recursive selection, and provide an ETag that identifies the downloaded object revision.
  • Preserve S3 folder-cache reuse only for unchanged selection settings, and clear the cache on shutdown or when the selected prefix, pattern, recursion, bucket, or logger changes.
  • Keep initialization checks aligned with retrieval and shutdown behavior for database and cache clients. A client that is not ready must not enter a refresh, and a closed client must report the correct not-ready state.

Important failure modes

TriggerConsequenceGuard
A required source setting is emptyConfiguration validation rejects the retriever before startup.Supply the identity fields listed for the selected kind.
A retriever returns bytes in the wrong formatParsing fails and the manager does not publish that refresh.Match the source data to FileFormat or use the retriever's format hint.
A Git provider reaches its rate limitFurther reads fail until the provider's reset time.Use a token where needed and account for provider limits in polling.
GitHub App fields are incomplete, mixed with a personal token, or contain an invalid keyInitialization or token minting fails, so the repository file is not read.Supply a valid RSA key with the App ID and installation ID, or use a personal token instead.
GitHub cannot exchange the app JWT for an installation token, or the installation token is rejectedThe GitHub retrieval fails; a 401 gets one fresh-token retry before the error is returned.Grant the app access to the repository and keep its key, installation, endpoint, and clock settings valid.
Cloud credentials or the target object are unavailableThe source read fails and the current flag cache remains in use.Grant the process access and verify bucket, container, and object names.
S3 folder objects use mixed formatsThe folder retrieval fails before it produces a merged flag set.Store all selected S3 files in JSON, YAML, or TOML of one format.
Two selected S3 files define the same flagThe S3 retrieval fails instead of choosing one definition.Give each selected file unique flag names.
An S3 listing omits a page or reports a stale object versionThe merged flag set can miss files or reuse content after an object change.Walk every listing page and compare the downloaded object's ETag with the listed revision.
A database row or document has invalid flag dataThe adapter may omit invalid records or fail to produce usable JSON.Keep source records in the adapter's expected shape.
A PostgreSQL pool is released too many timesA shared pool can close while another retriever still expects it.Match each pool acquisition with one release.
MongoDB or Redis retrieval starts before initializationThe retriever returns an initialization error instead of flag data.Complete retriever initialization before the manager requests a read.
A Redis value is not valid JSONThe full Redis retrieval fails.Store each flag value as valid JSON.
A ConfigMap does not contain the requested keyThe Kubernetes retrieval fails.Store the complete flag document under the configured key.
Two retrievers define the same flagThe later source silently overrides the earlier definition.Treat retriever order as part of the configuration contract.

Key files

FileWhy to read it
retriever/retriever.goDefines the shared retrieval, lifecycle, readiness, and format contracts.
cmdhelpers/…/retriever_conf.goDefines supported kinds, common configuration fields, and required settings.
cmdhelpers/…/retriever_init.goMaps configuration kinds to source adapters and applies shared defaults.
retriever/manager.goShows how every adapter enters loading, parsing, merging, and refresh.
retriever/…/retriever.goShows the general remote endpoint contract and optional TLS access.
retriever/…/http.goProvides the common HTTP request behavior used by HTTP-based retrievers.
retriever/…/retriever.goShows repository-file access, GitHub App authentication, and provider rate-limit handling.
retriever/…/jwt.goShows the GitHub App token signing contract.
retriever/…/retriever_app_test.goVerifies GitHub App authentication, token reuse and refresh, retry behavior, and configuration errors.
retriever/…/jwt_internal_test.goVerifies failure handling when JWT signing cannot use the supplied RSA key.
retriever/…/retriever.goShows GitLab repository-file access and safe handling of repository and file path values.
retriever/…/retriever_test.goVerifies GitLab retrieval, defaults, errors, authentication, and path handling.
retriever/…/retriever.goShows S3 item and folder retrieval modes, client setup, lifecycle, and output format selection.
retriever/…/store.goShows the S3 listing and download boundary used by folder retrieval.
internal/…/loader.goShows provider-independent folder selection, version cache, format checks, parsing, and merging.
retriever/…/retriever_test.goVerifies S3 item and folder behavior, format preservation, cache reuse, listing, pagination, and failure handling.
retriever/…/retriever.goShows object metadata checks and local content reuse.
retriever/…/retriever.goShows table rows becoming a JSON flag document.
retriever/…/postgres.goShows URI-keyed PostgreSQL pool sharing and release.
retriever/…/postgres_test.goVerifies pool reuse, reference release, and recreation with live PostgreSQL.
retriever/…/retriever.goShows MongoDB document mapping, readiness, and JSON output.
retriever/…/retriever_unit_test.goVerifies that MongoDB retrieval rejects use before initialization.
retriever/…/retriever.goShows Redis client lifecycle, key scanning, prefix handling, and JSON assembly.
retriever/…/retriever_unit_test.goVerifies that Redis retrieval rejects use before initialization.
retriever/…/retriever.goShows ConfigMap data retrieval and missing-key behavior.