confx-knowledge

Load and manage Go application configuration from TCC, files, and environment variables.

Updated Apr 30, 2026
One-click install
npx skills add https://github.com/yuezhen-huang/my-bytedance-skillhub --skill confx-knowledge-yuezhen-huang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: confx-knowledge
Source: https://github.com/yuezhen-huang/my-bytedance-skillhub/tree/main/confx-knowledge
Command: npx skills add https://github.com/yuezhen-huang/my-bytedance-skillhub --skill confx-knowledge-yuezhen-huang

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go services often need to load configuration from multiple sources such as TCC, local files, environment variables, KMS, or Byteconf, and keeping that logic consistent, testable, and hot-reloadable is repetitive and error-prone. This Skill provides the knowledge to use the confx library (code.byted.org/gopkg/confx) for unified multi-source configuration management. ## Core Features & Use Cases - Static and Dynamic Configuration: Load one-time static config from YAML/JSON files or declare dynamic config as function fields with periodic refresh, default values, and change callbacks. - Multiple Configuration Sources: Use built-in TCC (V2/V3), file, and environment variable loaders, or extend with KMS, Byteconf, and custom Loader/Parser factories. - Production Safeguards: Apply required initialization checks, deepcopy protection against data races, runtime key selection, Mock support for unit tests, and Grafana monitoring metrics. - Use Case: A service needs a feature flag that updates without redeployment. Declare GetEnableFeatureA func() bool with a confx:"tcc:enable_feat_a" tag, call confx.MustInit, and the value refreshes automatically every 10 seconds. ## Quick Start Ask the AI to show how to load a dynamic boolean feature flag from TCC using the confx library in a Go service.

Frequently Asked Questions about confx-knowledge

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I load dynamic configuration from TCC in Go?

Declare a function field with a confx struct tag, such as `GetEnableFeatureA func() bool \`confx:"tcc:enable_feat_a"\``, then call confx.MustInit. The value refreshes automatically every 10 seconds by default, configurable via WithRefreshInterval.

How to load config from a YAML file per environment in Go?

Use the file loader with a confx tag like `confx:"file:service_conf"` and pass WithLoaderKeyMap to map the key to an environment-specific path, for example conf/service_config.{region}.yml. Files ending in .yml or .yaml are parsed as YAML automatically.

Does confx support TCC V3 configuration?

Yes, confx supports TCC V3 by setting the path parameter in the tag, passing cli_version:v3, or enabling the global WithTCCV3 option. Without these, it uses the TCC V2 client in compatibility mode, which reads both V2 and V3 /default directories.

confx vs easyswitch for dynamic config, what is the difference?

confx supports deepcopy, json/yaml parsing, callbacks, and custom loaders like easyswitch, but differs on TCC default PSM handling, lacks active RefreshValue and TCC V1 support, and does not support dynamic updates on pointer fields to avoid data races.

Why is my confx config not updating after a TCC change?

The field is likely declared as a static value instead of a func() field, so it is loaded only once. Also check for json.Unmarshal errors in logs and Grafana, and note that without deepcopy, mutations by one goroutine affect the shared cached value.

How do I mock confx configuration in unit tests?

Use mock.NewBuilder from code.byted.org/gopkg/confx/mock to mock static values with MockValue and dynamic function fields with MockFunc, then call Build. Call Restore on the mocker afterward to recover the original state.