utils

package
v4.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: GPL-3.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	IP4arpa = ".in-addr.arpa."
	IP6arpa = ".ip6.arpa."
)

Variables

This section is empty.

Functions

func BytesToStringUnsafe

func BytesToStringUnsafe(b []byte) string

BytesToStringUnsafe converts bytes to string.

func CheckNumRange added in v4.3.0

func CheckNumRange[K constraints.Integer | constraints.Float](v, min, max K) bool

func ClosedChan

func ClosedChan(c chan struct{}) bool

ClosedChan returns true if c is closed. c must not use for sending data and must be used in close() only. If ClosedChan receives something from c, it panics.

func GenerateCertificate

func GenerateCertificate(dnsName string) (cert tls.Certificate, err error)

GenerateCertificate generates an ecdsa certificate with given dnsName. This should only use in test.

func GetAddrFromAddr added in v4.3.0

func GetAddrFromAddr(addr net.Addr) netip.Addr

GetAddrFromAddr returns netip.Addr from net.Addr. See also: GetIPFromAddr.

func GetIPFromAddr

func GetIPFromAddr(addr net.Addr) (ip net.IP)

GetIPFromAddr returns a net.IP from the given net.Addr. addr can be *net.TCPAddr, *net.UDPAddr, *net.IPNet, *net.IPAddr Will return nil otherwise.

func LoadCertPool

func LoadCertPool(certs []string) (*x509.CertPool, error)

LoadCertPool reads and loads certificates in certs.

func ParsePTRName added in v4.2.0

func ParsePTRName(fqdn string) (netip.Addr, error)

func RemoveComment

func RemoveComment(s, symbol string) string

RemoveComment removes comment after "symbol".

func SetDefaultNum added in v4.2.0

func SetDefaultNum[K constraints.Integer | constraints.Float](p *K, d K)

func SplitLineReg

func SplitLineReg(s string) []string

SplitLineReg extracts words from s by using regexp "\S+".

func SplitSchemeAndHost

func SplitSchemeAndHost(addr string) (protocol, host string)

SplitSchemeAndHost splits addr to protocol and host.

func SplitString2

func SplitString2(s, symbol string) (s1 string, s2 string, ok bool)

SplitString2 split s to two parts by given symbol

func WeakDecode

func WeakDecode(in map[string]interface{}, output interface{}) error

WeakDecode decodes args from config to output.

Types

type Errors

type Errors []error

func (*Errors) Append

func (es *Errors) Append(err error)

func (*Errors) Build

func (es *Errors) Build() error

func (*Errors) Error

func (es *Errors) Error() string

func (*Errors) String

func (es *Errors) String() string

Jump to

Keyboard shortcuts

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