Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CancelAll ¶
func CancelAll(cancels ...func())
CancelAll executes all provided cancel functions. It is typically used for cleaning up or aborting operations that were started earlier and can be cancelled.
Parameters:
cancels: A slice of cancel functions, each of type func(). These are typically functions returned by context.WithCancel, or similar functions that provide a way to cancel an operation.
Example:
var cancels []func()
ctx, cancel := context.WithCancel(context.Background()) cancels = append(cancels, cancel)
// Later, when all operations need to be cancelled: CancelAll(cancels)
Note: The caller is responsible for handling any errors that may occur during the execution of the cancel functions.
func GetRandomWait ¶
GetRandomWait returns a random duration between the specified minWait and maxWait durations. The function takes the minimum and maximum wait times as arguments, creates a new random number generator with a seed based on the current Unix timestamp, and calculates the random wait time within the given range.
Example usage:
minWait := 2 * time.Second maxWait := 6 * time.Second randomWaitTime := GetRandomWait(minWait, maxWait)
Parameters:
minWait: The minimum duration to wait. maxWait: The maximum duration to wait.
Returns:
time.Duration: A random duration between minWait and maxWait.
func Wait ¶
Wait generates a random period of time anchored to a given input value.
Parameters:
near: A float64 value that serves as the base value for generating the random wait time.
Returns:
time.Duration: The calculated random wait time in milliseconds. error: An error if the generation of the random wait time fails.
The function is useful for simulating more human-like interaction in the context of a web application. It first calculates a 'zoom' value by dividing the input 'near' by 10. Then, a random number is generated in the range of [0, zoom), and added to 95% of 'near'. This sum is then converted to a time duration in milliseconds and returned.
Example:
waitTime, err := Wait(1000.0)
if err != nil {
log.Fatalf("failed to generate random wait time: %v", err)
}
log.Printf("Generated random wait time: %v\n", waitTime)
Types ¶
type Browser ¶
type Browser struct {
Driver interface{}
Cancels []func()
}
Browser defines parameters used for driving a web browser.
type Credential ¶
Credential contains the information that makes up a credential to authenticate to an application.
type Driver ¶
type Driver interface {
GetContext() context.Context
SetContext(context.Context)
GetOptions() []chromedp.ExecAllocatorOption
SetOptions([]chromedp.ExecAllocatorOption)
}
Driver is an interface that can be implemented for various browsers in go. It should service to capture information such as context and browser options.
type LoginOption ¶
type LoginOption func(*loginOptions)
LoginOption is a type for functions that modify the login options. These functions take a pointer to a loginOptions struct and modify it in place.
func WithLogout ¶
func WithLogout(enabled bool) LoginOption
WithLogout is a function that returns a LoginOption function which sets the logMeOut option.
Parameters:
enabled: Determines if the user should be logged out after login.
Returns:
LoginOption: A function that modifies the logMeOut option of a loginOptions struct.
func WithTwoFac ¶
func WithTwoFac(enabled bool) LoginOption
WithTwoFac is a function that returns a LoginOption function which sets the twoFacEnabled option.
Parameters:
enabled: Determines if two-factor authentication should be enabled during login.
Returns:
LoginOption: A function that modifies the twoFacEnabled option of a loginOptions struct.
type Session ¶
type Session struct {
Credential Credential
Driver interface{}
}
Session contains parameters associated with maintaining a session.