Documentation
¶
Overview ¶
Package bootstrap performs process startup before Wire: it optionally syncs remote Nacos configuration, loads the local conf.yaml into viper, applies APP_* environment overrides and validates app.env and production secrets.
This package intentionally uses viper and reads environment variables: it is the documented startup exception (analogous to go-nacos). Request-path kit packages (core, errcode, middleware) never depend on it.
Index ¶
- Constants
- Variables
- func ApplyEnvOverrides()
- func IsPlaceholderSecret(v string) bool
- func Run(opts Options) error
- func RunContext(ctx context.Context, opts Options) error
- func SetupViperFromPath(configDir string, secretKeys ...string) error
- func SyncFromNacos(opts NacosOptions) error
- func SyncFromNacosContext(ctx context.Context, opts NacosOptions) error
- func ValidateAppEnv(env string) error
- func ValidateSecrets(env string, keys ...string) error
- type NacosClient
- type NacosClientFactory
- type NacosOptions
- type Options
Constants ¶
const ( // DefaultConfigDir is the directory containing conf.yaml. DefaultConfigDir = "./config" // DefaultConfigPath is the local application config file path. DefaultConfigPath = "./config/conf.yaml" )
const DefaultRelationPath = "./config/conf.yaml"
DefaultRelationPath is the local application config file updated from Nacos.
Variables ¶
var DefaultProdSecretKeys = []string{
"mysql.default.password",
"jwt.secret",
"security.blind_index_key",
}
DefaultProdSecretKeys are the keys that must be non-placeholder outside development (values should come from Nacos or APP_* env).
Functions ¶
func ApplyEnvOverrides ¶
func ApplyEnvOverrides()
ApplyEnvOverrides enables APP_* environment overrides for nested keys (e.g. APP_MYSQL_DEFAULT_PASSWORD → mysql.default.password).
func IsPlaceholderSecret ¶
IsPlaceholderSecret reports whether v is empty or a known unsafe placeholder.
func Run ¶
Run syncs remote Nacos config (optional) and loads local YAML into viper. It is RunContext with context.Background (the Nacos watch is never cancelled).
func RunContext ¶
RunContext is Run with a caller-controlled ctx: cancelling ctx stops the Nacos config watch and aborts an in-flight download.
func SetupViperFromPath ¶
SetupViperFromPath loads conf.yaml, watches changes, validates app.env, applies APP_* overrides, and rejects placeholder secrets for testing/staging/production (which expect Nacos-provided config). Optional secretKeys are forwarded to ValidateSecrets; empty uses DefaultProdSecretKeys.
func SyncFromNacos ¶
func SyncFromNacos(opts NacosOptions) error
SyncFromNacos downloads and watches remote config when not skipped. The watch lives for the whole process; use SyncFromNacosContext for a cancellable watch.
func SyncFromNacosContext ¶
func SyncFromNacosContext(ctx context.Context, opts NacosOptions) error
SyncFromNacosContext downloads remote config and registers a watch that is cancelled when ctx is done.
func ValidateAppEnv ¶
ValidateAppEnv checks app.env against allowed values.
func ValidateSecrets ¶
ValidateSecrets rejects empty/placeholder secrets for non-development environments. Logging AES masking was removed in go-logging v0.2; app.aes.key is no longer required (mobile encrypt uses aes.backend.key / aes.frontend.key).
Types ¶
type NacosClient ¶
type NacosClient interface {
Download(ctx context.Context) (string, error)
Watch(ctx context.Context, onChange func(content []byte) error) error
}
NacosClient is the subset of the go-nacos client used by bootstrap (injectable for tests).
type NacosClientFactory ¶
type NacosClientFactory func(cfg libNacos.Config) (NacosClient, error)
NacosClientFactory builds a NacosClient from Config.
type NacosOptions ¶
type NacosOptions struct {
SkipNacosFlag string
ConfigPath string
MetaPaths []string
OnNacosChange func(error)
// ClientFactory overrides how the Nacos client is built (tests); nil uses go-nacos.
ClientFactory NacosClientFactory
}
NacosOptions configures remote Nacos sync.
type Options ¶
type Options struct {
SkipNacos bool
SkipNacosFlag string
ConfigDir string
ConfigPath string
MetaPaths []string
OnNacosChange func(error)
// ClientFactory overrides how the Nacos client is built (tests); nil uses go-nacos.
ClientFactory NacosClientFactory
// SecretKeys overrides DefaultProdSecretKeys when non-empty (e.g. gRPC
// processes that validate grpc.auth.token instead of security.blind_index_key).
SecretKeys []string
}
Options controls process bootstrap before Wire.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns common bootstrap defaults.