utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CookiesToHeader

func CookiesToHeader(allCookies map[string][]*http.Cookie) string

func CreateHttpClient

func CreateHttpClient(proxies string) (tlsClient.HttpClient, error)

func IsNumeric

func IsNumeric(s string) bool

IsNumeric checks if a string contains only numeric characters. Used to distinguish between numeric IDs and usernames.

Parameters:

  • s: the string to check

Returns:

  • bool: true if string contains only digits

Example:

IsNumeric("123456") // returns true
IsNumeric("user123") // returns false
IsNumeric("") // returns false

func MakeRequest

func MakeRequest(client tlsClient.HttpClient, config RequestConfig) ([]byte, *http.Response, error)

MakeRequest handles HTTP requests with proper header ordering and error handling

func RandomSleep

func RandomSleep(min, max int)

RandomSleep sleeps for a random duration between min and max seconds

func Sleep

func Sleep(seconds int)

Sleep sleeps for the exact number of seconds

Types

type CookieClient

type CookieClient struct {
	Cookies []http.Cookie
}

func NewCookieClient

func NewCookieClient() *CookieClient

func (*CookieClient) AddCookies

func (jar *CookieClient) AddCookies(cookies []http.Cookie)

func (*CookieClient) CookiesToHeader

func (jar *CookieClient) CookiesToHeader() string

CookiesToHeader this function converts cookies from the []cycletls.Cookie{} format to a header format that simply contains a string of all cookies in the name=value format;

func (*CookieClient) GetCookieValue

func (jar *CookieClient) GetCookieValue(name string) (string, bool)

func (*CookieClient) SetCookieFromResponse

func (jar *CookieClient) SetCookieFromResponse(resp *http.Response)

type HeaderPair

type HeaderPair struct {
	Key   string
	Value string
}

HeaderPair represents a header key-value pair

type LogLevel

type LogLevel int

LogLevel defines the verbosity of logging

const (
	LogLevelNone    LogLevel = iota // No logging
	LogLevelError                   // Only errors
	LogLevelWarning                 // Errors and warnings
	LogLevelSuccess                 // Errors, warnings, and success messages
	LogLevelInfo                    // Normal operational logs
	LogLevelDebug                   // Detailed debug information
)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(level LogLevel) Logger

func (Logger) Debug

func (l Logger) Debug(format string, a ...any) error

func (Logger) Error

func (l Logger) Error(format string, a ...any) error

func (Logger) Info

func (l Logger) Info(format string, a ...any) error

func (Logger) Success

func (l Logger) Success(format string, a ...any) error

func (Logger) Warning

func (l Logger) Warning(format string, a ...any) error

type RequestConfig

type RequestConfig struct {
	Method  string
	URL     string
	Body    io.Reader
	Headers []HeaderPair
}

RequestConfig contains all possible options for making a request

func DefaultConfig

func DefaultConfig() RequestConfig

DefaultConfig returns common Twitter request headers and their order

Jump to

Keyboard shortcuts

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