config

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 4 Imported by: 2

README

Secured Web Addressability Network

Secured Web Addressability Network (SWAN) - Config Go

Common configuration for Go. Used by projects like owid-go and swift-go to retrieve settings at startup.

The environment variables are checked for values to override any values contained in the configuration file or that are absent from the configuration file. Field names in the configuration structure are converted from camel case to the popular upper case underscore separated environment variable key format. For example; the field name ServiceProvider in a structure will be read from the environment variable SERVICE_PROVIDER if present.

Structures used with the LoadConfig function should use the mapstructure identifier to identify fields to be read from configuration files. For example; the field ServiceProvider should be declared as follows.

ServiceProvider string `mapstructure:"serviceProvider"`

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(paths []string, fileName string, i interface{}) error

LoadConfig populates the fields of interface i with the values from json configuration files in the paths provided and from environment variables that match the interface field names.

paths is an array of directories to look for configuration files. fileName is the name of the configuration file. The extension must be a type supported by the viper package (JSON, TOML, YAML, HCL, envfile and Java properties config). i is an instance of an interface to be populated from the files and environment variables identified.

The method converts camel case field names to environment variables inserting an underscore before upper case characters and outputting all characters as uppercase. For example; the camel case field name ServicePath would become SERVICE_PATH. The interface that is being used for the configuration needs to be consulted because viper passes an upper case version of the field name into the method.

Types

type Base added in v0.1.5

type Base struct {
	AzureStorageAccount   string `mapstructure:"azureStorageAccount"`
	AzureStorageAccessKey string `mapstructure:"azureStorageAccessKey"`
	GcpProject            string `mapstructure:"gcpProject"`
	AwsEnabled            bool   `mapstructure:"awsEnabled"`
	Scheme                string `mapstructure:"scheme"` // Either https or http
	Debug                 bool   `mapstructure:"debug"`  // True for debug logging
	HttpPlatformPort      int    `mapstructure:"httpPlatformPort"`
	HttpsPlatformPort     int    `mapstructure:"httpsPlatformPort"`
	Port                  int    `mapstructure:"port"`
}

Configuration details from appsettings.json for access to the AWS, GCP, Azure or local file storage.

func (*Base) GetPortHTTP added in v0.1.5

func (b *Base) GetPortHTTP() int

func (*Base) GetPortHTTPS added in v0.1.5

func (b *Base) GetPortHTTPS() int

Jump to

Keyboard shortcuts

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