The Feature service is the backend for managing feature flags (key/value pairs).
It exposes functionality that can be consumed by the feature CLI and other clients.
The service binary is also called feature, but its primary entrypoint here is the service subcommand (see below).
From the service directory:
cd service
go build -o featureThis produces a feature binary that can run the service and utility commands.
feature [global flags] <command> [command flags]The service defines global flags (for logging) and subcommands:
version– print the service versionservice– start the Feature service
These flags are defined at the root level and apply to all subcommands.
- Env var:
LOG_FORMAT - Default:
text - Allowed values:
text,json - Category:
logging - Description: Log output format for the service.
- Env var:
LOG_LEVEL - Default:
info - Allowed values:
debug,info,warn,error - Category:
logging - Description: Minimum log level emitted by the service.
Example:
feature --log-format json --log-level debug service ...Prints the Feature service name and version (derived from meta.Service and meta.Version).
feature versionThis does not start the server; it only logs the version information.
Starts the Feature service process.
feature service [flags]All of the following flags are defined on the service subcommand.
- Flag name:
port - Type: integer
- Env var:
PORT - Default:
8080 - Category:
service - Description: Port on which the Feature service will listen.
Example:
feature service --port 8000
PORT=8000 feature service- Flag name:
enable-opentelemetry - Type: boolean
- Env var:
ENABLE_OPENTELEMETRY - Default:
false - Category:
observability - Description: Enable OpenTelemetry tracing for the service.
Example:
feature service --enable-opentelemetry
ENABLE_OPENTELEMETRY=true feature service- Flag name:
otlp-endpoint - Type: string
- Env var:
OTLP_ENDPOINT - Default:
localhost:4317 - Category:
observability - Description: OTLP collector endpoint used when OpenTelemetry is enabled.
Example:
feature service \
--enable-opentelemetry \
--otlp-endpoint otel-collector:4317- Flag name:
storage-type - Type: string
- Env var:
STORAGE_TYPE - Default:
inmemory(fromconstant.StorageTypeInMemory) - Description: Storage backend for feature data.
Allowed values (validated in code):
inmemory– in‑memory storage (non‑persistent; data lost on restart).configmap– use a Kubernetes ConfigMap as storage.
When storage-type is configmap, --configmap-name must be set; otherwise the service will fail validation.
Example:
# In-memory storage (default)
feature service --storage-type inmemory
# ConfigMap-based storage
feature service \
--storage-type configmap \
--configmap-name my-feature-flags- Flag name:
configmap-name - Type: string
- Env var:
CONFIGMAP_NAME - Description: Name of the Kubernetes ConfigMap used when
storage-typeisconfigmap.
If storage-type=configmap and configmap-name is empty, the process will return an error:
configmap-name cannot be empty when storage-type is configmap
Example:
feature service \
--storage-type configmap \
--configmap-name feature-flags- Flag name:
preset - Type: string slice (
key=valuepairs) - Env var:
PRESET - Description: Pre-set key/value pairs before starting the service.
Each value must be in the formatkey=value. Multiple values can be provided by repeating the flag.
Examples:
# CLI syntax
feature service \
--preset featureA=enabled \
--preset featureB=disabled
# Environment variable (depending on how urfave/cli parses string slices)
PRESET=featureA=enabled,featureB=disabled feature service- Flag name:
editable - Type: string
- Env var:
EDITABLE - Default:
""(empty - all fields editable) - Category:
service - Description: Comma-separated list of field names that can be edited. When set, enforces field-level access control:
- Only listed fields can be updated
- New fields cannot be created
- No fields can be deleted (all fields protected)
- Non-listed fields become read-only
- Empty value means all operations are allowed
Behavior:
When EDITABLE="" (default):
- ✅ Create new fields
- ✅ Update any field
- ✅ Delete any field
When EDITABLE="FIELD1,FIELD2":
- ❌ Creating new fields blocked
- ✅ Update FIELD1 and FIELD2 only
- ❌ Update other fields (read-only)
- ❌ Delete any field (all protected)
Note: The --preset flag always bypasses editable restrictions, allowing baseline configuration to be established.
Examples:
# Allow editing only MAINTENANCE_FLOW and DEBUG_MODE
feature service --editable "MAINTENANCE_FLOW,DEBUG_MODE"
# Environment variable
EDITABLE=MAINTENANCE_FLOW,DEBUG_MODE feature service
# Combined with preset (preset always works regardless of editable)
feature service \
--preset COLOR=red \
--preset THEME=dark \
--preset MAINTENANCE_FLOW=disabled \
--editable "MAINTENANCE_FLOW"Before any command runs, the beforeAction hook:
- Reads
--log-formatand--log-level. - Validates and maps
log-leveltosloglevels. - Creates either a JSON or text handler:
- JSON:
slog.NewJSONHandler(os.Stdout, ...) - Text:
slog.NewTextHandler(os.Stdout, ...)
- JSON:
- Sets a global default logger for the process with
slog.SetDefault.
If an invalid log level is supplied, the command fails with:
invalid log level: <value>
Start the service with default settings:
feature serviceStart on a custom port with JSON logs and debug level:
feature \
--log-format json \
--log-level debug \
service \
--port 8000Enable OpenTelemetry and point to a custom OTLP endpoint:
feature \
--log-format json \
--log-level info \
service \
--enable-opentelemetry \
--otlp-endpoint otel-collector.observability:4317Use ConfigMap storage with some pre-set features:
feature \
--log-format text \
--log-level info \
service \
--storage-type configmap \
--configmap-name feature-flags \
--preset featureA=enabled \
--preset featureB=disabledUse field-level access control to restrict editing:
# Set up baseline configuration with only MAINTENANCE_FLOW editable
feature service \
--preset COLOR=red \
--preset THEME=dark \
--preset MAINTENANCE_FLOW=disabled \
--preset DEBUG_MODE=false \
--editable "MAINTENANCE_FLOW,DEBUG_MODE"
# In this configuration:
# - COLOR and THEME cannot be modified (read-only)
# - MAINTENANCE_FLOW and DEBUG_MODE can be updated
# - No new fields can be created
# - No fields can be deletedPrint version information only:
feature versionThe --editable flag enables fine-grained control over which feature flags can be modified at runtime.
- Production Environments: Lock down critical configuration values while allowing operational toggles to be changed
- Multi-Tenant Scenarios: Provide different access levels for different teams
- Configuration Management: Prevent accidental deletion or creation of flags
- Immutable Baselines: Use
--presetto establish configurations that cannot be changed later
When editable restrictions are active:
- GetAll RPC: Returns an
editable: boolfield for each feature flag indicating whether it can be modified - Set RPC: Returns
PermissionDeniederror for:- Non-editable fields:
"field 'FIELD_NAME' is not editable" - New field creation:
"creating new fields is not allowed when editable restrictions are active"
- Non-editable fields:
- Delete RPC: Returns
PermissionDeniederror:"deleting fields is not allowed when editable restrictions are active" - PreSet RPC: Always succeeds regardless of editable configuration (for initial setup)
# Trying to update a read-only field
$ grpcurl -d '{"key":"COLOR","value":"blue"}' localhost:8000 feature.v1.Feature/Set
ERROR:
Code: PermissionDenied
Message: field 'COLOR' is not editable
# Trying to create a new field
$ grpcurl -d '{"key":"NEW","value":"value"}' localhost:8000 feature.v1.Feature/Set
ERROR:
Code: PermissionDenied
Message: creating new fields is not allowed when editable restrictions are active
# Trying to delete a field
$ grpcurl -d '{"name":"MAINTENANCE_FLOW"}' localhost:8000 feature.v1.Feature/Delete
ERROR:
Code: PermissionDenied
Message: deleting fields is not allowed when editable restrictions are active