configurator

package
v1.3.15 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: MIT Imports: 7 Imported by: 0

README

Config

Simple configuration

Why:

Every single program uses configuration in the form of settings or env vars

How:

environment.config.json

{
  "name": "hi",
  "app": {
    "port": "3000",
    "maxRequests": 1.2
  }
}


golang struct:

type AppSettings struct {
	Port        string
	MaxRequests float64
}

// Settings contains the config.yml settings
type Settings struct {
	// App
	Name string      `mapstructure:"name"`
	App  AppSettings `mapstructure:"app"`
}

Note: Avoid using underscores and stick to using camelCase. Instead of max_requests use maxRequests.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configurator

type Configurator struct {
	Environment string
	// contains filtered or unexported fields
}

func New added in v0.1.6

func New(opts ...Option) (*Configurator, error)

New returns a new Configurator instance

func (*Configurator) LoadConfiguration added in v1.0.0

func (cfg *Configurator) LoadConfiguration(output any) error

LoadConfiguration loads configuration files into an interface based on the environment

func (*Configurator) LoadEnvVars added in v1.0.0

func (cfg *Configurator) LoadEnvVars(output any) error

LoadEnvVars loads the environment variables into an interface

func (*Configurator) LoadEnvVarsAndConfig added in v1.0.0

func (cfg *Configurator) LoadEnvVarsAndConfig(envVarsOutput, configOutput any) error

func (*Configurator) LoadEnvVarsFromFile added in v1.0.0

func (cfg *Configurator) LoadEnvVarsFromFile(output any) error

LoadEnvVarsFromFile loads the environment variables from a file into an interface

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithConfigPath

func WithConfigPath(path string) Option

func WithEnvPath

func WithEnvPath(path string) Option

func WithOptionalEnv

func WithOptionalEnv(env string) Option

func WithRequiredEnv

func WithRequiredEnv(env string) Option

Jump to

Keyboard shortcuts

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