config

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package config contains the functionality for reading in and loosely validating config files. The configuration is exposed via package level public variables. These must never be changed on the fly and instead configured via the config file or env vars

Env variables will override the config values. They can all be set using the same format as shown to map to the correct config keys:

export discord.token=TOKEN_TOKEN_TOKEN_TOKEN_TOKEN
export general.steam_key=STEAM_KEY_STEAM_KEY_STEAM_KEY
./gbans serve

Index

Constants

View Source
const (
	// Release is production mode, minimal logging
	Release runMode = "release"
	// Debug has much more logging and uses non-embedded assets
	Debug runMode = "debug"
	// Test is for unit tests
	Test runMode = "test"
)

Variables

View Source
var (
	General generalConfig
	HTTP    httpConfig
	Filter  filterConfig
	Relay   relayConfig
	DB      dbConfig
	Discord discordConfig
	Log     logConfig
	Net     netBans
	RPC     rpcConfig
)

Default config values. Anything defined in the config or env will override them

Functions

func DefaultExpiration

func DefaultExpiration() time.Time

DefaultExpiration returns the default expiration time delta from Now()

func FmtDuration added in v0.1.3

func FmtDuration(t time.Time) string

FmtDuration calculates and returns a string for duration differences. This handles values larger than a day unlike the stdlib in functionalities

func FmtTimeShort added in v0.1.3

func FmtTimeShort(t time.Time) string

FmtTimeShort returns a common format for time display

func Now

func Now() time.Time

Now returns the current time in the configured format of the application runtime

All calls to time.Now() should use this instead to ensure consistency

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration works exactly like time.ParseDuration except that it supports durations longer than hours Formats: s, m, h, d, w, M, y

func Read

func Read(cfgFiles ...string)

Read reads in config file and ENV variables if set.

Types

type Action added in v0.1.6

type Action string
const (
	Gag  Action = "gag"
	Kick Action = "kick"
	Ban  Action = "ban"
)

type BanList

type BanList struct {
	URL  string      `mapstructure:"url"`
	Name string      `mapstructure:"name"`
	Type BanListType `mapstructure:"type"`
}

BanList holds details to load a ban lost

type BanListType

type BanListType string

BanListType is the type or source of a ban list

const (
	// CIDR formatted list
	CIDR BanListType = "cidr"
	// ValveNet is the srcds network ban list format
	ValveNet BanListType = "valve_net"
	// ValveSID is the srcds steamid ban list format
	ValveSID BanListType = "valve_steamid"
	// TF2BD sources ban list
	TF2BD BanListType = "tf2bd"
)

Jump to

Keyboard shortcuts

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