config

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddConfigPath

func AddConfigPath(configPath string)

AddConfigPath sets a custom config path.

func Load

func Load(c any) *errors.Error

Load loads the configuration into the input interface. The method returns an *errors.Error if:

  • there is an error while loading the config.
  • the validation fails.

func SetConfigName

func SetConfigName(configName string)

SetConfigName sets a custom config name.

func SetConfigType

func SetConfigType(configType string)

SetConfigType sets a custom config type.

func Validate

func Validate(cnf any) *errors.Error

Validate checks if all the required configuration is set. Required fields are identified by the struct tag required. The method returns an *errors.Error if the required fields are not set.

Types

type ServerConfig

type ServerConfig struct {
	Protocol              string `mapstructure:"SERVER_PROTOCOL"`
	Host                  string `mapstructure:"SERVER_HOST" required:"true"`
	Port                  string `mapstructure:"SERVER_PORT" required:"true"`
	LogLevel              string `mapstructure:"SERVER_LOG_LEVEL"`
	StaticFilesRoot       string `mapstructure:"STATIC_FILES_ROOT"`
	HTMLTemplateFilesRoot string `mapstructure:"HTML_TEMPLATE_FILES_ROOT"`
}

ServerConfig represents the default server configuration.

func LoadServerConfig

func LoadServerConfig() (*ServerConfig, *errors.Error)

LoadServerConfig loads configuration from the environment and returns a ServerConfig instance. If values are not provided for ServerConfig.Host and ServerConfig.Port a error will be returned and if values are not provided for ServerConfig.Protocol and ServerConfig.StaticFilesRoot a default value is set. default values:

ServerConfig.Protocol =  https
ServerConfig.StaticFilesRoot = /
ServerConfig.HTMLTemplateFilesRoot = /

Jump to

Keyboard shortcuts

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