config

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package config has specific primitives for loading application configurations.

Primitives:

  • Application should have struct for containing configuration. E.g. refer propeller/internal/config/config.go file.
  • Application should have a directory holding default file and environment specific file. E.g. refer propeller/configs/* directory.

Usage:

  • E.g. NewDefaultConfig().Load("dev", &config), where config is a struct where configuration gets unmarshalled into.

Index

Constants

View Source
const (
	DefaultConfigType     = "toml"
	DefaultConfigDir      = "./config"
	DefaultConfigFileName = "propeller"
	FilePath              = "PROPELLER_CONFIG_FILE_PATH"
)

Default options for configuration loading.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config is a wrapper over a underlying config loader implementation.

func NewConfig

func NewConfig(opts Options) *Config

NewConfig returns new config struct.

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig returns new config struct with default options.

func (*Config) Load

func (c *Config) Load(fileName string, config interface{}) error

Load reads environment specific configurations and along with the defaults unmarshalls into config.

type Options

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

Options is config options.

func NewDefaultOptions

func NewDefaultOptions() Options

NewDefaultOptions returns default options. DISCLAIMER: This function is a bit hacky This function expects an env $WORKDIR to be set and reads configs from $WORKDIR/configs. If $WORKDIR is not set. It uses the absolute path wrt the location of this file (config.go) to set configPath to 2 levels up in viper (../../configs). This function breaks if : 1. $WORKDIR is set and configs dir not present in $WORKDIR 2. $WORKDIR is not set and ../../configs is not present 3. $WORKDIR is not set and runtime absolute path of configs is different than build time path as runtime.Caller() evaluates only at build time

func NewOptions

func NewOptions(configType string, configPath string, defaultConfigFileName string) Options

NewOptions returns new Options struct.

Jump to

Keyboard shortcuts

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