updated ezconf
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
//
|
||||
// ezconf allows you to:
|
||||
// - Load configurations from multiple packages using their ConfigFromEnv functions
|
||||
// - Parse package source code to extract environment variable documentation
|
||||
// - Parse config struct tags to extract environment variable documentation
|
||||
// - Generate and update .env files with all required environment variables
|
||||
// - Print environment variable lists with descriptions and current values
|
||||
// - Track additional custom environment variables
|
||||
@@ -40,16 +40,16 @@
|
||||
// // Use configuration...
|
||||
// }
|
||||
//
|
||||
// Alternatively, you can manually register packages:
|
||||
// Alternatively, you can manually register config structs:
|
||||
//
|
||||
// loader := ezconf.New()
|
||||
//
|
||||
// // Add package paths to parse for ENV comments
|
||||
// loader.AddPackagePath("/path/to/golib/hlog")
|
||||
// // Add config struct for tag parsing
|
||||
// loader.AddConfigStruct(&mypackage.Config{}, "MyPackage")
|
||||
//
|
||||
// // Add configuration loaders
|
||||
// loader.AddConfigFunc("hlog", func() (interface{}, error) {
|
||||
// return hlog.ConfigFromEnv()
|
||||
// loader.AddConfigFunc("mypackage", func() (interface{}, error) {
|
||||
// return mypackage.ConfigFromEnv()
|
||||
// })
|
||||
//
|
||||
// loader.Load()
|
||||
@@ -94,27 +94,34 @@
|
||||
// Default: "postgres://localhost/mydb",
|
||||
// })
|
||||
//
|
||||
// # ENV Comment Format
|
||||
// # Struct Tag Format
|
||||
//
|
||||
// ezconf parses struct field comments in the following format:
|
||||
// ezconf uses struct tags to define environment variable metadata:
|
||||
//
|
||||
// type Config struct {
|
||||
// // ENV LOG_LEVEL: Log level for the application (default: info)
|
||||
// LogLevel string
|
||||
//
|
||||
// // ENV DATABASE_URL: Database connection string (required)
|
||||
// DatabaseURL string
|
||||
// LogLevel string `ezconf:"LOG_LEVEL,description:Log level for the application,default:info"`
|
||||
// DatabaseURL string `ezconf:"DATABASE_URL,description:Database connection string,required"`
|
||||
// LogDir string `ezconf:"LOG_DIR,description:Directory for log files,required:when LOG_OUTPUT is file"`
|
||||
// }
|
||||
//
|
||||
// The format is:
|
||||
// - ENV ENV_VAR_NAME: Description (optional modifiers)
|
||||
// - (required) or (required if condition) - marks variable as required
|
||||
// - (default: value) - specifies default value
|
||||
// Tag components (comma-separated):
|
||||
// - First value: environment variable name (required)
|
||||
// - description:...: Description of the variable
|
||||
// - default:...: Default value
|
||||
// - required: Marks the variable as required
|
||||
// - required:condition: Marks as required with a condition description
|
||||
//
|
||||
// # Integration
|
||||
//
|
||||
// Packages can implement the Integration interface to provide automatic
|
||||
// registration with ezconf. The interface requires:
|
||||
// - Name() string: Registration key for the config
|
||||
// - ConfigPointer() any: Pointer to config struct for tag parsing
|
||||
// - ConfigFunc() func() (any, error): Function to load config from env
|
||||
// - GroupName() string: Display name for grouping env vars
|
||||
//
|
||||
// ezconf integrates with:
|
||||
// - All golib packages that follow the ConfigFromEnv pattern
|
||||
// - Any custom configuration structs with ENV comments
|
||||
// - Any custom configuration structs with ezconf struct tags
|
||||
// - Standard .env file format
|
||||
package ezconf
|
||||
|
||||
Reference in New Issue
Block a user