utils

package
v1.0.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: 0

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