utils

package
v0.0.0-...-a50b361 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CookieJarFromFile

func CookieJarFromFile(filePath string) (*cookiejar.Jar, error)

CookieJarFromFile loads cookies from Mozilla cookies.sqlite or Netscape cookies.txt

func ExtractDomain

func ExtractDomain(url string) string

ExtractDomain extracts domain from URL

func FileExtension

func FileExtension(filename string) string

FileExtension returns the file extension (including the dot) from a filename or URL. If the filename starts with a dot and has no other dot, it returns an empty string (e.g., ".hiddenfile" -> ""). If there is no extension, it returns an empty string.

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes converts bytes to human readable string

func FormatDuration

func FormatDuration(seconds time.Duration) string

FormatDuration formats a duration in seconds to a human-readable string

func IsValidURL

func IsValidURL(url string) bool

IsValidURL checks if the string is a valid URL

func MergeHeader

func MergeHeader(original, additional http.Header) http.Header

MergeHeader merges two http.Header objects into one.

func SanitizeFilename

func SanitizeFilename(filename string) string

SanitizeFilename removes invalid characters from filename

Types

type RateLimiter

type RateLimiter struct {
	io.Reader

	Rate int64 // bytes per second
	// contains filtered or unexported fields
}

RateLimiter wraps an io.Reader and limits the read speed to the specified bytes per second. RateLimiter implements io.ReadCloser for compatibility with io.ReadCloser chains.

func NewRateLimiter

func NewRateLimiter(r io.Reader, rate int64) *RateLimiter

NewRateLimiter creates a new RateLimiter for the given reader and rate (bytes/sec).

func (*RateLimiter) Close

func (rl *RateLimiter) Close() error

Close closes the underlying reader if possible.

func (*RateLimiter) Read

func (rl *RateLimiter) Read(p []byte) (int, error)

Read reads data from the underlying reader, limiting the speed.

Jump to

Keyboard shortcuts

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