Documentation
¶
Index ¶
- Constants
- func AddTrailingSlashBytes(b []byte) []byte
- func AddTrailingSlashString(s string) string
- func AppendInt(dst []byte, n int64) []byte
- func AppendUint(dst []byte, n uint64) []byte
- func ByteSize(bytes uint64) string
- func ConvertToBytes(humanReadableString string) int
- func CopyBytes(b []byte) []byte
- func CopyString(s string) string
- func EqualFold[S byteSeq](b, s S) bool
- func FormatInt(n int64) string
- func FormatInt16(n int16) string
- func FormatInt32(n int32) string
- func FormatInt8(n int8) string
- func FormatUint(n uint64) string
- func FormatUint16(n uint16) string
- func FormatUint32(n uint32) string
- func FormatUint8(n uint8) string
- func FunctionName(fn any) string
- func GenerateSecureToken(length int) string
- func GetArgument(arg string) bool
- func GetMIME(extension string) string
- func IncrementIPRange(ip net.IP)
- func IsIPv4(s string) bool
- func IsIPv6(s string) bool
- func ParseFloat32[S byteSeq](s S) (float32, error)
- func ParseFloat64[S byteSeq](s S) (float64, error)
- func ParseInt[S byteSeq](s S) (int64, error)
- func ParseInt16[S byteSeq](s S) (int16, error)
- func ParseInt32[S byteSeq](s S) (int32, error)
- func ParseInt8[S byteSeq](s S) (int8, error)
- func ParseUint[S byteSeq](s S) (uint64, error)
- func ParseUint16[S byteSeq](s S) (uint16, error)
- func ParseUint32[S byteSeq](s S) (uint32, error)
- func ParseUint8[S byteSeq](s S) (uint8, error)
- func ParseVendorSpecificContentType(cType string, caseInsensitive ...bool) string
- func ReadFile(path string, fs http.FileSystem) ([]byte, error)
- func SecureToken() string
- func StartTimeStampUpdater()
- func StatusMessage(status int) string
- func StopTimeStampUpdater()
- func Timestamp() uint32
- func ToLower(b string) string
- func ToLowerBytes(b []byte) []byte
- func ToString(arg any, timeFormat ...string) string
- func ToUpper(b string) string
- func ToUpperBytes(b []byte) []byte
- func Trim[S byteSeq](s S, cutset byte) S
- func TrimLeft[S byteSeq](s S, cutset byte) S
- func TrimRight[S byteSeq](s S, cutset byte) S
- func TrimSpace[S byteSeq](s S) S
- func UUID() string
- func UUIDv4() string
- func UnsafeBytes(s string) []byte
- func UnsafeString(b []byte) string
- func Walk(fs http.FileSystem, root string, walkFn filepath.WalkFunc) error
- type CBORMarshal
- type CBORUnmarshal
- type JSONMarshal
- type JSONUnmarshal
- type MsgPackMarshal
- type MsgPackUnmarshal
- type Signed
- type Unsigned
- type XMLMarshal
- type XMLUnmarshal
Constants ¶
const MIMEOctetStream = "application/octet-stream"
Variables ¶
This section is empty.
Functions ¶
func AddTrailingSlashBytes ¶
AddTrailingSlashBytes appends a trailing '/' to b if it does not already end with one. If the input already ends with '/', the original slice is returned. A new slice is returned when a '/' is appended. The original slice is never modified.
func AddTrailingSlashString ¶
AddTrailingSlashString appends a trailing '/' to s if it does not already end with one. If the input already ends with '/', the original string is returned. A new string is returned only when a '/' needs to be appended.
func AppendUint ¶
AppendUint appends the decimal string representation of n to dst.
func ByteSize ¶
ByteSize returns a human-readable byte string of the form 10M, 12.5K, and so forth. The unit that results in the smallest number greater than or equal to 1 is always chosen. Maximum supported input is math.MaxUint64 / 10 (≈ 1844674407370955161).
func ConvertToBytes ¶
ConvertToBytes returns integer size of bytes from human-readable string, ex. 42kb, 42M Returns 0 if string is unrecognized
func EqualFold ¶
func EqualFold[S byteSeq](b, s S) bool
EqualFold tests ascii strings or bytes for equality case-insensitively
func FormatInt ¶
FormatInt formats an int64 as a decimal string. It is faster than strconv.FormatInt for most inputs.
func FormatInt16 ¶
FormatInt16 formats an int16 as a decimal string.
func FormatInt32 ¶
FormatInt32 formats an int32 as a decimal string.
func FormatUint ¶
FormatUint formats a uint64 as a decimal string. It is faster than strconv.FormatUint for most inputs.
func FormatUint16 ¶
FormatUint16 formats a uint16 as a decimal string.
func FormatUint32 ¶
FormatUint32 formats a uint32 as a decimal string.
func FormatUint8 ¶
FormatUint8 formats a uint8 as a decimal string.
func GenerateSecureToken ¶
GenerateSecureToken generates a cryptographically secure random token encoded in base64. It uses crypto/rand for randomness and base64.RawURLEncoding for URL-safe output. If length is less than or equal to 0, it defaults to 32 bytes (256 bits of entropy). Panics if the random source fails.
func IncrementIPRange ¶
IncrementIPRange Find available next IP address
func IsIPv4 ¶
IsIPv4 works the same way as net.ParseIP, but without check for IPv6 case and without returning net.IP slice, whereby IsIPv4 makes no allocations.
func IsIPv6 ¶
IsIPv6 works the same way as net.ParseIP, but without check for IPv4 case and without returning net.IP slice, whereby IsIPv6 makes no allocations.
func ParseFloat32 ¶
ParseFloat32 parses a decimal ASCII string or byte slice into a float32. It returns (0, false) on error or if the parsed value overflows float32.
func ParseFloat64 ¶
ParseFloat64 parses a decimal ASCII string or byte slice into a float64. It delegates the actual parsing to parseFloat.
func ParseInt ¶
ParseInt parses a decimal ASCII string or byte slice into an int64. Returns the parsed value and nil on success, else 0 and an error.
func ParseInt16 ¶
ParseInt16 parses a decimal ASCII string or byte slice into an int16.
func ParseInt32 ¶
ParseInt32 parses a decimal ASCII string or byte slice into an int32.
func ParseUint ¶
ParseUint parses a decimal ASCII string or byte slice into a uint64. It returns the parsed value and nil on success. If the input contains non-digit characters, it returns 0 and an error.
func ParseUint16 ¶
ParseUint16 parses a decimal ASCII string or byte slice into a uint16.
func ParseUint32 ¶
ParseUint32 parses a decimal ASCII string or byte slice into a uint32.
func ParseUint8 ¶
ParseUint8 parses a decimal ASCII string or byte slice into a uint8.
func ParseVendorSpecificContentType ¶
ParseVendorSpecificContentType check if content type is vendor specific and if it is parsable to any known types. If its not vendor specific then returns the original content type.
func ReadFile ¶
func ReadFile(path string, fs http.FileSystem) ([]byte, error)
ReadFile returns the raw content of a file
func SecureToken ¶
func SecureToken() string
SecureToken generates a secure token with 32 bytes of entropy. Panics if the random source fails. See GenerateSecureToken for details.
func StartTimeStampUpdater ¶
func StartTimeStampUpdater()
StartTimeStampUpdater launches a background goroutine that updates the cached timestamp every second. It is safe to call multiple times; only the first call will start the updater.
func StatusMessage ¶
StatusMessage returns the correct message for the provided HTTP statuscode
func StopTimeStampUpdater ¶
func StopTimeStampUpdater()
StopTimeStampUpdater stops the background updater goroutine. Call this on app shutdown to avoid leaking goroutines.
func Timestamp ¶
func Timestamp() uint32
Timestamp returns the current cached Unix timestamp (seconds). Call StartTimeStampUpdater() once at app startup for best performance.
func ToLowerBytes ¶
ToLowerBytes converts ascii slice to lower-case
func ToUpperBytes ¶
ToUpperBytes converts ascii slice to upper-case
func TrimLeft ¶
func TrimLeft[S byteSeq](s S, cutset byte) S
TrimLeft is the equivalent of strings/bytes.TrimLeft
func TrimRight ¶
func TrimRight[S byteSeq](s S, cutset byte) S
TrimRight is the equivalent of strings/bytes.TrimRight
func TrimSpace ¶
func TrimSpace[S byteSeq](s S) S
TrimSpace removes leading and trailing whitespace from a string or byte slice. This is an optimized version that's faster than strings/bytes.TrimSpace for ASCII strings. It removes the following ASCII whitespace characters: space, tab, newline, carriage return, vertical tab, and form feed.
func UUID ¶
func UUID() string
UUID generates an universally unique identifier (UUID). This is an alias for UUIDv4 for backward compatibility.
func UUIDv4 ¶
func UUIDv4() string
UUIDv4 returns a Random (Version 4) UUID. The strength of the UUIDs is based on the strength of the crypto/rand package.
func UnsafeBytes ¶
UnsafeBytes returns a byte pointer without allocation.
func UnsafeString ¶
UnsafeString returns a string pointer without allocation
Types ¶
type CBORMarshal ¶
CBORMarshal returns the CBOR encoding of v.
type CBORUnmarshal ¶
CBORUnmarshal parses the CBOR-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an error.
type JSONMarshal ¶
JSONMarshal returns the JSON encoding of v.
type JSONUnmarshal ¶
JSONUnmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.
type MsgPackMarshal ¶
MsgPackMarshal returns the MsgPack encoding of v.
type MsgPackUnmarshal ¶
MsgPackUnmarshal parses the MsgPack-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.
type XMLMarshal ¶
XMLMarshal returns the XML encoding of v.
type XMLUnmarshal ¶
XMLUnmarshal parses the XML-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.