utils

package
v0.9.23 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 22 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

View Source
var ProtectedKeys = ``

Functions

func BindToInterface added in v0.9.0

func BindToInterface(name string) func(network, address string, conn syscall.RawConn) error

func Decode

func Decode(input any, output any) error

Decode is an alias to a mapstructure.NewDecoder({Squash: true}).Decode() with WeaklyTypedInput set to true and MatchFunc that only compares aplhanumeric sequence in field names

func Decrypt

func Decrypt(cfg []byte) (result []byte, protected bool, err error)

Decrypt decrypts config using EncryptionKeys

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 GetEnvFloatDefault added in v0.9.3

func GetEnvFloatDefault(key string, defaultValue float64) float64

GetEnvFloatDefault 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 InfiniteRange added in v0.8.23

func InfiniteRange[T any](ctx context.Context, input []T) chan T

It could've been more effective if go had yield but this should be close enough

func IsEncrypted

func IsEncrypted(cfg []byte) bool

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

func Max added in v0.9.3

func Max[T int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64](a, b T) T

func NonNilOrDefault added in v0.8.16

func NonNilOrDefault[T any](v *T, dflt T) T

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 ToMiB added in v0.9.18

func ToMiB(bytes uint64) uint64

func Unmarshal added in v0.7.9

func Unmarshal(input []byte, output any, format string) error

func UpdateRLimit added in v0.8.23

func UpdateRLimit() error

Types

type BackoffConfig added in v0.8.11

type BackoffConfig struct {
	Multiplier int
	Limit      int
	Timeout    time.Duration
}

func DefaultBackoffConfig added in v0.8.11

func DefaultBackoffConfig() BackoffConfig

type BackoffController added in v0.8.11

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

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
	// contains filtered or unexported fields
}

func (*Counter) Next added in v0.8.11

func (c *Counter) Next() bool

type Locker added in v0.9.14

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

func (*Locker) Lock added in v0.9.14

func (m *Locker) Lock(key string) func()

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(ctx context.Context, params ProxyParams, protocol string) ProxyFunc

this won't work for udp payloads but if people use proxies they might not want to have their ip exposed so it's probably better to fail instead of routing the traffic directly

type ProxyParams added in v0.9.0

type ProxyParams struct {
	URLs         string
	DefaultProto string
	LocalAddr    string
	Interface    string
	Timeout      time.Duration
}

Directories

Path Synopsis
Package metrics collects and reports job metrics.
Package metrics collects and reports job metrics.
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