util

package
v0.0.0-...-3a8821d Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendPrefixMask

func AppendPrefixMask(ipStr string, maskSize int) (string, error)

AppendPrefixMask appends a prefix mask to a v4 or v6 address and returns the result as a string.

func CLose

func CLose(err *error, fn fnWithErrorResult)

func CheckPeriodically

func CheckPeriodically(ctx context.Context, duration time.Duration, fn func() (bool, error)) (bool, error)

CheckPeriodically checks a function (fn) at a specified interval (duration). It will return when one of these conditions occurs: fn returns true, fn returns an error, the duration is met, or the context is Done().

func ContainsValidCustomIPv4Ranges

func ContainsValidCustomIPv4Ranges(ipRanges []string) bool

ContainsValidCustomIPv4Ranges matches the following custom IPv4 patterns usable by netfilter userspace utils: Cidr notation 100.100.0.0/16 Individual address 10.100.0.2 Dash-separated range 100.100.0.0-100.100.10.255

func ContainsValidCustomIPv6Ranges

func ContainsValidCustomIPv6Ranges(ipRanges []string) bool

ContainsValidCustomIPv6Ranges matches the following custom IPv6 patterns usable by netfilter userspace utils: Cidr notation 200::/64 Individual address 200::2 Dash-separated range 200::1-200::8 Dash-separated range 2001:0db8:0000:0000:0000:0000:0000:0000-2001:0db8:ffff:ffff:ffff:ffff:ffff:ffff

func FilterOutAllowed

func FilterOutAllowed(elems []string, allowed map[string]struct{}) (notAllowed []string)

func Getenv

func Getenv(name, defaultValue string) string

func GetenvDuration

func GetenvDuration(name, defaultValue string) (time.Duration, error)

func GetenvInt

func GetenvInt(name, defaultValue string) (int, error)

func GoWithWaitGroup

func GoWithWaitGroup(wg *sync.WaitGroup, fn func())

GoWithWaitGroup runs fn in a goroutine with an optional *sync.WaitGroup to track when fn finishes executing.

func IPNetSliceToStringSlice

func IPNetSliceToStringSlice(items []net.IPNet) (result []string)

func IgnoreError

func IgnoreError(fn fnWithErrorResult)

IgnoreError call the passed fn and ignore the errors it returns. Example `defer util.IgnoreError(file.Close)`

func IsDefaultIPRoute

func IsDefaultIPRoute(ip string) bool

IsDefaultIPRoute wrapper for IsDefaultIPv4Route and IsDefaultIPv6Route

func IsDefaultIPv4Route

func IsDefaultIPv4Route(ip string) bool

IsDefaultIPv4Route checks if the given prefix is the default route for IPv4.

func IsDefaultIPv6Route

func IsDefaultIPv6Route(ip string) bool

IsDefaultIPv6Route checks if the given prefix is the default route for IPv6.

func IsIPv4Address

func IsIPv4Address(addr string) bool

IsIPv4Address checks if the given IP address is an IPv4 address.

func IsIPv4Prefix

func IsIPv4Prefix(prefix string) bool

IsIPv4Prefix checks if the given IP address is an IPv4 prefix.

func IsIPv6Address

func IsIPv6Address(addr string) bool

IsIPv6Address checks if the given IP address is an IPv6 address.

func IsIPv6Prefix

func IsIPv6Prefix(prefix string) bool

IsIPv6Prefix checks if the given IP address is an IPv6 prefix.

func IsValidPrefix

func IsValidPrefix(prefix string) bool

IsValidPrefix checks if the given cidr is valid

func JsonStringer

func JsonStringer(x interface{}) fmt.Stringer

func JsonUnmarshal

func JsonUnmarshal(from map[string]interface{}, to interface{}) error

func MustJsonMarshalToString

func MustJsonMarshalToString(x interface{}) string

func ParseTime

func ParseTime(timeStr string) (time.Time, error)

ParseTime attempts to parse a time string in three possible formats to handle UTC and local time differences between Darwin and Linux and the proxy mode. On each system we get different time formats for the last wireguard handshake time.

func PtrString

func PtrString(v string) *string

func RetryOperation

func RetryOperation(ctx context.Context, wait time.Duration, retries int, operation func() error) error

RetryOperation retries the operation with a backoff policy.

func RetryOperationExpBackoff

func RetryOperationExpBackoff(ctx context.Context, maxWait time.Duration, operation func() error) error

RetryOperationExpBackoff retries the operation with an exponential backoff policy.

func RetryOperationForErrors

func RetryOperationForErrors(ctx context.Context, wait time.Duration, retries int, retriableErrors []error, operation func() error) error

RetryOperationForErrors retries the operation with a backoff policy for the specified errors, otherwise will just perform the operation once and return the error if it fails.

func RunPeriodically

func RunPeriodically(ctx context.Context, duration time.Duration, fn func())

func SplitKeyValue

func SplitKeyValue(s string) (result []string)

func StringToInt64

func StringToInt64(s string) int64

func TimeBeginPeriod

func TimeBeginPeriod(period uint32) error

func TimeEndPeriod

func TimeEndPeriod(period uint32) error

func ValidateIPv4Cidr

func ValidateIPv4Cidr(cidrStr string) error

ValidateIPv4Cidr checks for a valid IPv4 cidr

func ValidateIPv6Cidr

func ValidateIPv6Cidr(cidrStr string) error

ValidateIPv6Cidr checks for a valid IPv6 cidr

func WithTrace

func WithTrace(ctx context.Context, l *zap.SugaredLogger) *zap.SugaredLogger

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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