utils

package
v0.0.49 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowOnly added in v0.0.19

func AllowOnly[T any](format func(T) string, allowed []T) func(T) error

AllowOnly returns a validator function that permits only values from the given list. Each value is compared using the provided formatting function. The format function is used to normalize or stringify values for comparison, which is useful for case-insensitive or structured types.

func FormatBytes

func FormatBytes(b uint64) string

FormatBytes uint64 → string

func FormatFile

func FormatFile(f *os.File) string

FormatFile *os.File → string

func FormatFloat32

func FormatFloat32(f float32) string

FormatFloat32 float32 → string

func FormatFloat64

func FormatFloat64(f float64) string

FormatFloat64 time.Duration → string

func FormatIP

func FormatIP(ip net.IP) string

FormatIP net.IP → string

func FormatIPv4Mask

func FormatIPv4Mask(ip net.IPMask) string

FormatIPv4Mask net.IPMask → string

func FormatList added in v0.0.19

func FormatList[T any](format func(T) string, values []T) []string

FormatList applies the given format function to each element of the slice and returns a new slice of formatted strings. This is useful for preparing human-readable output from a slice of structured types.

func FormatString

func FormatString(s string) string

FormatString string → string

func FormatTCPAddr

func FormatTCPAddr(addr *net.TCPAddr) string

FormatTCPAddr *net.TCPAddr → string

func FormatTime

func FormatTime(t time.Time) string

FormatTime time.Time → string

func JoinFormatted added in v0.0.19

func JoinFormatted[T any](values []T, format func(T) string) string

JoinFormatted applies the given format function to each value and joins them with commas. If format is nil, it falls back to using fmt.Sprintf("%v", values).

func ParseBytes

func ParseBytes(s string) (uint64, error)

ParseBytes string → uint64

func ParseFile

func ParseFile(s string) (*os.File, error)

ParseFile string → *os.File

func ParseFloat32

func ParseFloat32(s string) (float32, error)

ParseFloat32 string → float32

func ParseFloat64

func ParseFloat64(s string) (float64, error)

ParseDuration string → time.Duration

func ParseIP

func ParseIP(s string) (net.IP, error)

ParseIP net.IP → string

func ParseIPv4Mask

func ParseIPv4Mask(s string) (net.IPMask, error)

ParseIPv4Mask string → net.IPMask

func ParseString

func ParseString(s string) (string, error)

ParseString string → string

func ParseTCPAddr

func ParseTCPAddr(s string) (*net.TCPAddr, error)

ParseTCPAddr string → *net.TCPAddr

func ParseTime

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

ParseTime string → time.Time

func PluralSuffix

func PluralSuffix(i int) string

PluralSuffix returns "s" if the given number is not 1, otherwise it returns an empty string. It is useful for constructing basic pluralized words like "flag" or "flags".

Types

This section is empty.

Jump to

Keyboard shortcuts

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