gs_conf

package
v1.2.2-rc Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package gs_conf provides hierarchical configuration management with multi-source support for Go-Spring framework.

Key Features:

1. Command-line argument parsing

  • Supports `-D key[=value]` format arguments
  • Customizable prefix via `GS_ARGS_PREFIX` environment variable
  • Example: `./app -D server.port=8080 -D debug`

2. Environment variable handling

  • Automatic loading of `GS_` prefixed variables
  • Conversion rules: `GS_DB_HOST=127.0.0.1` → `db.host=127.0.0.1`
  • Direct mapping of non-prefixed environment variables

3. Configuration file management

  • Supports properties/yaml/toml/json formats
  • Local configurations: ./conf/app.{properties|yaml|toml|json}
  • Remote configurations: ./conf/remote/app.{properties|yaml|toml|json}
  • Profile-based configurations (e.g., app-dev.properties)

4. Layered configuration hierarchy

  • Priority order: System config → File config → Env variables → CLI arguments
  • Provides AppConfig (application context) and BootConfig (boot context)
  • High-priority configurations override lower ones

Index

Constants

View Source
const CommandArgsPrefix = "GS_ARGS_PREFIX"

CommandArgsPrefix defines the environment variable name used to override the default option prefix. This allows users to customize the prefix used for command-line options if needed.

Variables

View Source
var SysConf = conf.New()

SysConf is the builtin configuration.

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	LocalFile   *PropertySources // Configuration sources from local files.
	RemoteFile  *PropertySources // Configuration sources from remote files.
	RemoteProp  conf.Properties  // Remote properties.
	Environment *Environment     // Environment variables as configuration source.
	CommandArgs *CommandArgs     // Command line arguments as configuration source.
}

AppConfig represents a layered application configuration.

func NewAppConfig

func NewAppConfig() *AppConfig

NewAppConfig creates a new instance of AppConfig.

func (*AppConfig) Refresh

func (c *AppConfig) Refresh() (conf.Properties, error)

Refresh merges all layers of configurations into a read-only properties.

type BootConfig

type BootConfig struct {
	LocalFile   *PropertySources // Configuration sources from local files.
	Environment *Environment     // Environment variables as configuration source.
	CommandArgs *CommandArgs     // Command line arguments as configuration source.
}

BootConfig represents a layered boot configuration.

func NewBootConfig

func NewBootConfig() *BootConfig

NewBootConfig creates a new instance of BootConfig.

func (*BootConfig) Refresh

func (c *BootConfig) Refresh() (conf.Properties, error)

Refresh merges all layers of configurations into a read-only properties.

type CommandArgs

type CommandArgs struct{}

CommandArgs represents a structure for handling command-line parameters.

func NewCommandArgs

func NewCommandArgs() *CommandArgs

NewCommandArgs creates and returns a new CommandArgs instance.

func (*CommandArgs) CopyTo

func (c *CommandArgs) CopyTo(out *conf.MutableProperties) error

CopyTo processes command-line parameters and sets them as key-value pairs in the provided conf.Properties. Parameters should be passed in the form of `-D key[=value/true]`.

type ConfigType

type ConfigType string

ConfigType defines the type of configuration: local or remote.

const (
	ConfigTypeLocal  ConfigType = "local"
	ConfigTypeRemote ConfigType = "remote"
)

type Environment

type Environment struct{}

Environment represents the environment configuration.

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment initializes a new instance of Environment.

func (*Environment) CopyTo

func (c *Environment) CopyTo(p *conf.MutableProperties) error

CopyTo add environment variables that matches IncludeEnvPatterns and exclude environment variables that matches ExcludeEnvPatterns.

type NamedPropertyCopier

type NamedPropertyCopier struct {
	PropertyCopier
	Name string
}

NamedPropertyCopier defines the interface for copying properties with a name.

func NewNamedPropertyCopier

func NewNamedPropertyCopier(name string, p PropertyCopier) *NamedPropertyCopier

NewNamedPropertyCopier creates a new instance of NamedPropertyCopier.

func (*NamedPropertyCopier) CopyTo

type PropertyCopier

type PropertyCopier interface {
	CopyTo(out *conf.MutableProperties) error
}

PropertyCopier defines the interface for copying properties.

type PropertySources

type PropertySources struct {
	// contains filtered or unexported fields
}

PropertySources is a collection of configuration files.

func NewPropertySources

func NewPropertySources(configType ConfigType, configName string) *PropertySources

NewPropertySources creates a new instance of PropertySources.

func (*PropertySources) AddDir

func (p *PropertySources) AddDir(dirs ...string)

AddDir adds a or more than one extra directories.

func (*PropertySources) AddFile

func (p *PropertySources) AddFile(files ...string)

AddFile adds a or more than one extra files.

func (*PropertySources) Reset

func (p *PropertySources) Reset()

Reset resets all the extra files.

type SysConfig added in v1.2.2

type SysConfig struct {
	Environment *Environment // Environment variables as configuration source.
	CommandArgs *CommandArgs // Command line arguments as configuration source.
}

func (*SysConfig) Refresh added in v1.2.2

func (c *SysConfig) Refresh() (conf.Properties, error)

Jump to

Keyboard shortcuts

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