utils

package
v0.8.14 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package utils [general utility functions for the db1000n app]

Index

Constants

This section is empty.

Variables

View Source
var EncryptionKeys = `/45pB920B6DFNwCB/n4rYUio3AVMawrdtrFnjTSIzL4=`

EncryptionKeys random 32 byte key encoded into base64 string. Used by default for configs

Functions

func CheckCountry

func CheckCountry(countriesToAvoid []string, strictCountryCheck bool, proxyURLs string, maxFetchRetries int) (bool, string)

CheckCountry checks which country the app is running from and whether it is in the blacklist.

func CheckCountryOrFail added in v0.8.3

func CheckCountryOrFail(cfg *CountryCheckerConfig, proxyURLs string) string

CheckCountryOrFail checks the country of client origin by IP and exits the program if it is in the blacklist.

func Decode

func Decode(input interface{}, output interface{}) error

Decode is an alias to a mapstructure.NewDecoder({Squash: true}).Decode()

func Decrypt

func Decrypt(cfg []byte) ([]byte, error)

Decrypt decrypts config using EncryptionKeys

func GetEncryptionKeys

func GetEncryptionKeys() ([]string, error)

GetEncryptionKeys returns list of encryption keys from ENCRYPTION_KEYS env variable name or default value

func GetEnvBoolDefault

func GetEnvBoolDefault(key string, defaultValue bool) bool

GetEnvBoolDefault returns environment variable or default value if no env varible is present

func GetEnvDurationDefault

func GetEnvDurationDefault(key string, defaultValue time.Duration) time.Duration

GetEnvDurationDefault returns environment variable or default value if no env varible is present

func GetEnvIntDefault

func GetEnvIntDefault(key string, defaultValue int) int

GetEnvIntDefault returns environment variable or default value if no env varible is present

func GetEnvStringDefault

func GetEnvStringDefault(key, defaultValue string) string

GetEnvStringDefault returns environment variable or default value if no env varible is present

func IsEncrypted

func IsEncrypted(cfg []byte) bool

IsEncrypted returns true if cfg encrypted with age tool (https://github.com/FiloSottile/age)

func NonNilDurationOrDefault added in v0.8.0

func NonNilDurationOrDefault(d *time.Duration, dflt time.Duration) time.Duration

func NonNilIntOrDefault added in v0.8.0

func NonNilIntOrDefault(i *int, dflt int) int

func PanicHandler

func PanicHandler(logger *zap.Logger)

PanicHandler just stub it in the beginning of every major module invocation to prevent single module failure from crashing the whole app

func Sleep added in v0.8.11

func Sleep(ctx context.Context, t time.Duration) bool

func Unmarshal added in v0.7.9

func Unmarshal(input []byte, output interface{}, format string) error

Types

type BackoffConfig added in v0.8.11

type BackoffConfig struct {
	Multiplier int           `mapstructure:"backoff_multiplier"`
	Limit      int           `mapstructure:"backoff_limit"`
	Timeout    time.Duration `mapstructure:"backoff_timeout"`
}

func DefaultBackoffConfig added in v0.8.11

func DefaultBackoffConfig() BackoffConfig

func NonNilBackoffConfigOrDefault added in v0.8.13

func NonNilBackoffConfigOrDefault(c *BackoffConfig, defaultConfig BackoffConfig) *BackoffConfig

type BackoffController added in v0.8.11

type BackoffController struct {
	BackoffConfig
	// contains filtered or unexported fields
}

func NewBackoffController added in v0.8.11

func NewBackoffController(c *BackoffConfig) BackoffController

func (BackoffController) GetTimeout added in v0.8.11

func (c BackoffController) GetTimeout() time.Duration

func (*BackoffController) Increment added in v0.8.11

func (c *BackoffController) Increment() *BackoffController

func (*BackoffController) Reset added in v0.8.11

func (c *BackoffController) Reset()

type Counter added in v0.8.11

type Counter struct {
	Count int `mapstructure:"count,omitempty"`
	// contains filtered or unexported fields
}

func (*Counter) Next added in v0.8.11

func (c *Counter) Next() bool

type CountryCheckerConfig added in v0.8.3

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

func NewCountryCheckerConfigWithFlags added in v0.8.3

func NewCountryCheckerConfigWithFlags() *CountryCheckerConfig

NewGlobalConfigWithFlags returns a GlobalConfig initialized with command line flags.

type ProxyFunc added in v0.8.0

type ProxyFunc func(network, addr string) (net.Conn, error)

func GetProxyFunc added in v0.8.0

func GetProxyFunc(proxyURLs string, timeout time.Duration) ProxyFunc

Directories

Path Synopsis
Package metrics [everything related to metrics goes here]
Package metrics [everything related to metrics goes here]
Package ota [allows hot update and reload of the executable]
Package ota [allows hot update and reload of the executable]
Package templates [provides utility functions to enable templating in app configuration]
Package templates [provides utility functions to enable templating in app configuration]

Jump to

Keyboard shortcuts

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