bootstrap

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	// DefaultConfigDir is the directory containing conf.yaml.
	DefaultConfigDir = "./config"
	// DefaultConfigPath is the local application config file path.
	DefaultConfigPath = "./config/conf.yaml"
)
View Source
const DefaultRelationPath = "./config/conf.yaml"

DefaultRelationPath is the local application config file updated from Nacos.

Variables

View Source
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

func IsPlaceholderSecret(v string) bool

IsPlaceholderSecret reports whether v is empty or a known unsafe placeholder.

func Run

func Run(opts Options) error

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

func RunContext(ctx context.Context, opts Options) error

RunContext is Run with a caller-controlled ctx: cancelling ctx stops the Nacos config watch and aborts an in-flight download.

func SetupViperFromPath

func SetupViperFromPath(configDir string, secretKeys ...string) error

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

func ValidateAppEnv(env string) error

ValidateAppEnv checks app.env against allowed values.

func ValidateSecrets

func ValidateSecrets(env string, keys ...string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL