util

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllUnique added in v0.1.2

func AllUnique[T comparable](sl []T) bool

func DecodeOptions

func DecodeOptions(in io.ReadCloser, formatHint string, out any) error

DecodeOptions will attempt to decode the given reader into the given object. The formatHint is used to select the format of the document. If the formatHint is empty, the format is guessed from the document. The document is first treated as a go-template with some custom functions. This allows us to use environment variables and file contents in the config.

func Exec

func Exec(ctx context.Context, command string, args ...string) error

func ExecOutput

func ExecOutput(ctx context.Context, command string, args ...string) ([]byte, error)

func GenerateULA

func GenerateULA() (netip.Prefix, error)

GenerateULA generates a unique local address with a /48 prefix according to RFC 4193. The network is returned as a netip.Prefix.

func GetEnvDefault

func GetEnvDefault(key, def string) string

GetEnvDefault returns the value of an environment variable or a default value.

func GetEnvDurationDefault

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

GetEnvDurationDefault returns the value of an environment variable or a default value.

func GetEnvIntDefault

func GetEnvIntDefault(key string, def int) int

GetEnvIntDefault returns the value of an environment variable or a default value.

func MACtoEUI64

func MACtoEUI64(mac net.HardwareAddr) net.HardwareAddr

MACtoEUI64 converts a MAC address to an EUI-64 identifier.

func ParsePortRange

func ParsePortRange(s string) (start int, end int, err error)

ParsePortRange parses a port range string.

func Ping

func Ping(ctx context.Context, addr netip.Addr) error

Ping sends ICMP echo requests to the given address. The context must have a timeout set and is used for the duration of the ping. The function returns an error if no replies were received.

func Pointer

func Pointer[T any](t T) *T

func PrettyByteSize added in v0.1.2

func PrettyByteSize(b int64) string

func Random64

func Random64(prefix netip.Prefix) (netip.Prefix, error)

Random64 generates a random /64 prefix from a /48 prefix.

func RandomLocalMAC

func RandomLocalMAC() (net.HardwareAddr, error)

GetRandomLocalMAC returns a random MAC address from the host.

func ResolveTCPAddr added in v0.0.27

func ResolveTCPAddr(ctx context.Context, lookup string, maxRetries int) (net.Addr, error)

ResolveTCPAddr resolves a TCP address with retries and context.

func SetupLogging added in v0.1.6

func SetupLogging(logLevel string) *slog.Logger

func TimeToNTP

func TimeToNTP(t time.Time) uint64

TimeToNTP converts a time.Time object to a 64-bit NTP time.

func VerifyChainOnly

func VerifyChainOnly(rawCerts [][]byte, _ [][]*x509.Certificate) error

VerifyChainOnly is a function that can be used in a TLS configuration to only verify that the certificate chain is valid.

Types

type STUNLoggerFactory added in v0.1.3

type STUNLoggerFactory struct {
	*slog.Logger
}

func NewSTUNLoggerFactory added in v0.1.3

func NewSTUNLoggerFactory(logger *slog.Logger) *STUNLoggerFactory

func (*STUNLoggerFactory) NewLogger added in v0.1.3

func (f *STUNLoggerFactory) NewLogger(scope string) logging.LeveledLogger

Jump to

Keyboard shortcuts

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