config

package
v0.0.0-...-f1dd9c7 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

config package handles setting up, parsing, and storing all configuration settings for the application. The main package sets up an instance of this package and all other packages can use the "GetInstance" method to get a reference to the config struct and all of it's values

Index

Constants

View Source
const (
	// Environment names
	EnvDevelopment = "dev"
	EnvProduction  = "prod"
	EnvTesting     = "test"

	// Environment variable prefix
	EnvPrefix = "forex-clock_"

	// Environment variable where the path to an outside
	// configuration file is located
	ConfigLocation = EnvPrefix + "CONFIG"

	// API versions
	Version10 = "1.0"
)

Variables

View Source
var (

	// Supported API versions
	SupportedVersions = []string{Version10}
)

Functions

func Init

func Init()

Init creates a new config instance and initializes it

Types

type Config

type Config struct {

	// The environment the application is running in
	Environment string `json:"environment" env:"ENVIRONMENT" default:"dev"`

	// Name of the application
	Name string `json:"name" env:"NAME" default:"forex-clock"`

	// The current release version of the application
	ReleaseVersion string `json:"release-version" env:"RELEASE_VERSION" default:""`

	// Start time of the application
	StartTime time.Time

	// Settings for the database
	DB DB `json:"db"`

	// Settings for the logger
	Log Log `json:"log"`

	// Settings for the server
	Server Server `json:"server"`
}

Config is a struct containing all configuration settings for the application

func GetInstance

func GetInstance() *Config

GetInstance returns the initialized config instance

type DB

type DB struct {
	// The username to use when connecting to a DB server
	Username string `json:"username" env:"DB_USERNAME" default:""`
	// The password to use when connecting to a DB server
	Password string `json:"password" env:"DB_PASSWORD" default:""`
	// The name of the database to use
	DatabaseName string `json:"database-name" env:"DB_DB_NAME" default:""`
	// Struct containing information for TCP connections
	TCP DBTCP `json:"tcp"`
	// The max time (in seconds) to wait for operations to complete
	Timeout int `json:"timeout" env:"DB_TIMEOUT" default:"5"`
	// The database dialect to use
	Dialect string `json:"dialect" env:"DB_DIALECT" default:"mysql"`
}

Struct containing configuration settings for a database

type DBTCP

type DBTCP struct {
	// The host of a DB server
	Host string `json:"host" env:"DB_TCP_HOST" default:"localhost"`
	// The port of a DB server
	Port int `json:"port" env:"DB_TCP_PORT" default:"3306"`
}

Struct containing configuration settings for a database TCP connection

type Log

type Log struct {
	// The formatter to use
	Formatter string `json:"formatter" env:"LOG_FORMATTER" default:"text"`
	// The log level to use
	Level string `json:"level" env:"LOG_LEVEL" default:"info"`
}

Struct containing configuration settings for application logging

type Server

type Server struct {
	// Port the server should listen on
	Port int `json:"port" env:"SERVER_PORT" default:"6010"`
	// Various timeouts for the server
	Timeouts struct {
		// Timeout (in seconds) allowed for server read operations
		Read int `json:"read" env:"SERVER_READ_TIMEOUT" default:"30"`
		// Timeout (in seconds) allowed for server write operations
		Write int `json:"write" env:"SERVER_WRITE_TIMEOUT" default:"30"`
		// Timeout (in seconds) allowed for server to shutdown
		ShutDown int `json:"shutdown" env:"SERVER_SHUTDOWN_TIMEOUT" default:"5"`
	} `json:"timeouts"`
}

Struct containing configuration settings for the application server

Jump to

Keyboard shortcuts

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