netroutine

package module
v0.0.0-...-8017151 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: Unlicense Imports: 25 Imported by: 0

README

netroutine GoDoc Go Report Card

This package facilitates the creation and execution of network request routines. This is useful for automating web scraping jobs.

Installation

go get -u github.com/aidenesco/netroutine

Usage

import "github.com/aidenesco/netroutine"

func main() {
    routine := netroutine.NewRoutine()
    
    env, _ := netroutine.NewEnvironment(make(map[string]interface{}))

    env.Run(routine)

    fmt.Println(env.Status) // Success
  }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUniversalEnvironmentOption

func AddUniversalEnvironmentOption(option EnvironmentOption)

Types

type BodyToReader

type BodyToReader struct {
	ToKey string
}

func (*BodyToReader) Run

func (b *BodyToReader) Run(ctx context.Context, wce *Environment) (string, Status)

type BuilderJSON

type BuilderJSON struct {
	Values []struct {
		ToPath   []string
		Variable string
		Value    interface{}
		Complex  bool
	}
	ToKey string
}

func (*BuilderJSON) Run

func (b *BuilderJSON) Run(ctx context.Context, wce *Environment) (string, Status)

type BuilderString

type BuilderString struct {
	Variables []string
	Base      string
	ToKey     string
}

func (*BuilderString) Run

func (b *BuilderString) Run(ctx context.Context, wce *Environment) (string, Status)

type BuilderURLEncoded

type BuilderURLEncoded struct {
	Values []struct {
		ToPath    string
		Variables []string
		Value     string
		Complex   bool
	}
	ToKey string
}

func (*BuilderURLEncoded) Run

type DecodeBase64

type DecodeBase64 struct {
	FromKey string
	ToKey   string
}

func (*DecodeBase64) Run

func (b *DecodeBase64) Run(ctx context.Context, wce *Environment) (string, Status)

type DecodeURL

type DecodeURL struct {
	FromKey string
	ToKey   string
}

func (*DecodeURL) Run

func (b *DecodeURL) Run(ctx context.Context, wce *Environment) (string, Status)

type EncodeBase64

type EncodeBase64 struct {
	FromKey string
	ToKey   string
}

func (*EncodeBase64) Run

func (b *EncodeBase64) Run(ctx context.Context, wce *Environment) (string, Status)

type EncodeURL

type EncodeURL struct {
	FromKey string
	ToKey   string
}

func (*EncodeURL) Run

func (b *EncodeURL) Run(ctx context.Context, wce *Environment) (string, Status)

type Environment

type Environment struct {
	WorkingData map[string]interface{}
	ExportData  map[string]interface{}
	Status      Status
	Logs        []string

	Client *http.Client
	// contains filtered or unexported fields
}

func NewEnvironment

func NewEnvironment(data map[string]interface{}, options ...EnvironmentOption) (env *Environment, err error)

func (*Environment) FullLogs

func (wce *Environment) FullLogs() string

func (*Environment) LastLog

func (wce *Environment) LastLog() string

func (*Environment) Run

func (wce *Environment) Run(ctx context.Context, r *Routine)

func (*Environment) StatusString

func (wce *Environment) StatusString() string

func (*Environment) ToResult

func (wce *Environment) ToResult() *Result

type EnvironmentOption

type EnvironmentOption func(environment *Environment) error

func WithExportVar

func WithExportVar(key string, value interface{}) EnvironmentOption

func WithHTTPTimeout

func WithHTTPTimeout(duration time.Duration) EnvironmentOption

func WithProxyFunc

func WithProxyFunc(pf func(r *http.Request) (*url.URL, error)) EnvironmentOption

func WithProxyURL

func WithProxyURL(proxy string) EnvironmentOption

func WithRetryLimit

func WithRetryLimit(limit int) EnvironmentOption

func WithRetrySleep

func WithRetrySleep(duration time.Duration) EnvironmentOption

func WithSecret

func WithSecret(key, value string) EnvironmentOption

func WithTransport

func WithTransport(transport http.RoundTripper) EnvironmentOption

func WithUniqueTransport

func WithUniqueTransport() EnvironmentOption

func WithWorkingVar

func WithWorkingVar(key string, value interface{}) EnvironmentOption

type FlagToStatus

type FlagToStatus struct {
	FromKey string
	IfTrue  Status
	IfFalse Status
}

func (*FlagToStatus) Run

func (b *FlagToStatus) Run(ctx context.Context, wce *Environment) (string, Status)

type FlagToSubroutine

type FlagToSubroutine struct {
	FromKey string
	IfTrue  Routine
	IfFalse Routine
}

func (*FlagToSubroutine) Run

type FlagVariables

type FlagVariables struct {
	Vars  []string
	ToKey string
}

func (*FlagVariables) Run

func (b *FlagVariables) Run(ctx context.Context, wce *Environment) (string, Status)

type GenerateAppId

type GenerateAppId struct {
	ToKey string
}

func (*GenerateAppId) Run

func (b *GenerateAppId) Run(ctx context.Context, wce *Environment) (string, Status)

type GenerateString

type GenerateString struct {
	Base  string
	ToKey string
}

func (*GenerateString) Run

func (b *GenerateString) Run(ctx context.Context, wce *Environment) (string, Status)

type GenerateUUID

type GenerateUUID struct {
	ToKey string
}

func (*GenerateUUID) Run

func (b *GenerateUUID) Run(ctx context.Context, wce *Environment) (string, Status)

type HashMD5

type HashMD5 struct {
	FromKey string
	ToKey   string
}

func (*HashMD5) Run

func (b *HashMD5) Run(ctx context.Context, wce *Environment) (string, Status)

type HashSHA1

type HashSHA1 struct {
	FromKey string
	ToKey   string
}

func (*HashSHA1) Run

func (b *HashSHA1) Run(ctx context.Context, wce *Environment) (string, Status)

type LoadCookies

type LoadCookies struct {
	URL     string
	FromKey string
}

func (*LoadCookies) Run

func (b *LoadCookies) Run(ctx context.Context, wce *Environment) (string, Status)

type MathAdd

type MathAdd struct {
	Source1Key string
	Source2Key string
	ToKey      string
}

func (*MathAdd) Run

func (b *MathAdd) Run(ctx context.Context, wce *Environment) (string, Status)

type MathCeiling

type MathCeiling struct {
	FromKey string
	ToKey   string
}

func (*MathCeiling) Run

func (b *MathCeiling) Run(ctx context.Context, wce *Environment) (string, Status)

type MathDivide

type MathDivide struct {
	Source1Key string
	Source2Key string
	ToKey      string
}

func (*MathDivide) Run

func (b *MathDivide) Run(ctx context.Context, wce *Environment) (string, Status)

type MathFloor

type MathFloor struct {
	FromKey string
	ToKey   string
}

func (*MathFloor) Run

func (b *MathFloor) Run(ctx context.Context, wce *Environment) (string, Status)

type MathMultiply

type MathMultiply struct {
	Source1Key string
	Source2Key string
	ToKey      string
}

func (*MathMultiply) Run

func (b *MathMultiply) Run(ctx context.Context, wce *Environment) (string, Status)

type MathRound

type MathRound struct {
	FromKey string
	ToKey   string
}

func (*MathRound) Run

func (b *MathRound) Run(ctx context.Context, wce *Environment) (string, Status)

type MathSubtract

type MathSubtract struct {
	Source1Key string
	Source2Key string
	ToKey      string
}

func (*MathSubtract) Run

func (b *MathSubtract) Run(ctx context.Context, wce *Environment) (string, Status)

type MathTotal

type MathTotal struct {
	FromKey string
	ToKey   string
}

func (*MathTotal) Run

func (b *MathTotal) Run(ctx context.Context, wce *Environment) (string, Status)

type ParseCookie

type ParseCookie struct {
	URL        string
	CookieName string
	ToKey      string
	Required   bool
}

func (*ParseCookie) Run

func (b *ParseCookie) Run(ctx context.Context, wce *Environment) (string, Status)

type ParseHeader

type ParseHeader struct {
	Header   string
	ToKey    string
	Required bool
}

func (*ParseHeader) Run

func (b *ParseHeader) Run(ctx context.Context, wce *Environment) (string, Status)

type ParseJSON

type ParseJSON struct {
	ToKey     string
	Path      []string
	Recursive bool
	Required  bool
}

func (*ParseJSON) Run

func (b *ParseJSON) Run(ctx context.Context, wce *Environment) (string, Status)

type ParseLR

type ParseLR struct {
	Left      string
	Right     string
	ToKey     string
	Recursive bool
	Required  bool
}

func (*ParseLR) Run

func (b *ParseLR) Run(ctx context.Context, wce *Environment) (string, Status)

type ParseRegex

type ParseRegex struct {
	Regex    string
	ToKey    string
	Required bool
}

func (*ParseRegex) Run

func (b *ParseRegex) Run(ctx context.Context, wce *Environment) (string, Status)

type PromoteVariable

type PromoteVariable struct {
	FromKey string
}

func (*PromoteVariable) Run

func (b *PromoteVariable) Run(ctx context.Context, wce *Environment) (string, Status)

type RandomUA

type RandomUA struct {
	ToKey string
}

func (*RandomUA) Run

func (b *RandomUA) Run(ctx context.Context, wce *Environment) (string, Status)

type RecaptchaV2

type RecaptchaV2 struct {
	SiteURL      string
	Sitekey      string
	ToKey        string
	IsEnterprise bool
	CaptchaHost  string
}

func (*RecaptchaV2) Run

func (b *RecaptchaV2) Run(ctx context.Context, wce *Environment) (string, Status)

type RecaptchaV3

type RecaptchaV3 struct {
	SiteURL      string
	Sitekey      string
	MinScore     float64
	ToKey        string
	IsEnterprise bool
	CaptchaHost  string
}

func (*RecaptchaV3) Run

func (b *RecaptchaV3) Run(ctx context.Context, wce *Environment) (string, Status)

type Request

type Request struct {
	URL struct {
		URL       string
		Variables []string
		Complex   bool
	}
	BodyVar string
	Headers []struct {
		Key       string
		Value     string
		Variables []string
		Complex   bool
	}
	KeyChain []struct {
		Status     Status
		StatusCode int
		TextKey    string
	}
	Method         string
	IgnoreRedirect bool
}

func (*Request) Run

func (b *Request) Run(ctx context.Context, wce *Environment) (string, Status)

type Result

type Result struct {
	ExportData map[string]interface{}
	Status     string
	Logs       []string
}

type Routine

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

func NewRoutine

func NewRoutine(b ...Runnable) *Routine

func RoutineFromBytes

func RoutineFromBytes(raw []byte) (*Routine, error)

func (*Routine) ToBytes

func (r *Routine) ToBytes() ([]byte, error)

type Runnable

type Runnable interface {
	Run(ctx context.Context, wce *Environment) (message string, status Status)
	// contains filtered or unexported methods
}

type SaveCookies

type SaveCookies struct {
	URL   string
	ToKey string
}

func (*SaveCookies) Run

func (b *SaveCookies) Run(ctx context.Context, wce *Environment) (string, Status)

type SetCookie

type SetCookie struct {
	URL       string
	Name      string
	Value     string
	Variables []string
	Complex   bool
}

func (*SetCookie) Run

func (b *SetCookie) Run(ctx context.Context, wce *Environment) (string, Status)

type SetVariable

type SetVariable struct {
	ToKey string
	Value interface{}
}

func (*SetVariable) Run

func (b *SetVariable) Run(ctx context.Context, wce *Environment) (string, Status)

type SliceAppend

type SliceAppend struct {
	ToKey   string
	FromKey string
}

func (*SliceAppend) Run

func (b *SliceAppend) Run(ctx context.Context, wce *Environment) (string, Status)

type SliceMerge

type SliceMerge struct {
	ToKey    string
	Format   string
	FromKeys []string
}

func (*SliceMerge) Run

func (b *SliceMerge) Run(ctx context.Context, wce *Environment) (string, Status)

type SliceToSubroutine

type SliceToSubroutine struct {
	VariableKeys []string
	Routine      Routine
	FromKeys     []string
	IgnoreErrors bool
}

func (*SliceToSubroutine) Run

type Status

type Status int
const (
	Success Status = iota
	Fail
	Retry
	Error
	Custom
)

func (Status) String

func (s Status) String() string

type Subroutine

type Subroutine struct {
	Subroutine Routine
}

func (*Subroutine) Run

func (b *Subroutine) Run(ctx context.Context, wce *Environment) (string, Status)

type TimeAddDuration

type TimeAddDuration struct {
	ToKey       string
	TimeKey     string
	DurationKey string
}

func (*TimeAddDuration) Run

func (b *TimeAddDuration) Run(ctx context.Context, wce *Environment) (string, Status)

type TimeFlagPassed

type TimeFlagPassed struct {
	FromKey string
	ToKey   string
}

func (*TimeFlagPassed) Run

func (b *TimeFlagPassed) Run(ctx context.Context, wce *Environment) (string, Status)

type TimeFromFormatted

type TimeFromFormatted struct {
	FromKey string
	Format  string
	ToKey   string
}

func (*TimeFromFormatted) Run

type TimeFromUnix

type TimeFromUnix struct {
	ToKey   string
	FromKey string
}

func (*TimeFromUnix) Run

func (b *TimeFromUnix) Run(ctx context.Context, wce *Environment) (string, Status)

type TimeNowToVariable

type TimeNowToVariable struct {
	ToKey string
}

func (*TimeNowToVariable) Run

type TimeParseDuration

type TimeParseDuration struct {
	ToKey   string
	FromKey string
}

func (*TimeParseDuration) Run

type TimeToUnix

type TimeToUnix struct {
	ToKey   string
	FromKey string
}

func (*TimeToUnix) Run

func (b *TimeToUnix) Run(ctx context.Context, wce *Environment) (string, Status)

Jump to

Keyboard shortcuts

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