libgosiege

package
v0.0.0-...-088ff0d Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2015 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package libgosiege package define all the structs and functions necessary for Gosiege Inside this package there is some new flags for better parse CLI params There is a struct for save Urls to parse and retrive in different way Inside results.go different structs works together for handle all the statistics

Index

Constants

View Source
const (
	KB float64 = 1 << (10 * iota)
	MB
	GB
	TB
)

Define some useful constants

View Source
const (
	ErrorFormat = "Formatting error"
)

Error constant

Variables

This section is empty.

Functions

func ByteSize

func ByteSize(b float64) string

ByteSize formats a number into something human readable

func ParseAllInputFile

func ParseAllInputFile(fileName string, request *Requests)

ParseAllInputFile reads a file which contains urls defined like in example.txt and prepare a InputRequest struct

func ProcessData

func ProcessData(dataChannel chan *SimpleCounter, HC *CompareHeader, waitGroup *sync.WaitGroup)

ProcessData reads form dataChannel and update all the statistics This function is NOT thread-safe. It's not a good idea call this function multiple times

Types

type CompareHeader

type CompareHeader struct {
	PrintRegexp bool
	// contains filtered or unexported fields
}

CompareHeader is a struct which keeps all the regexs received via CLI

func NewCompareHeader

func NewCompareHeader() *CompareHeader

NewCompareHeader creates an empty CompareGeader struct

func (*CompareHeader) Add

func (ch *CompareHeader) Add(key, value string)

Add adds a key and a value to struct. value must be a regexp. If value doesn't compile into a regexp, this key-value will be skipped

func (*CompareHeader) CompareAll

func (ch *CompareHeader) CompareAll(header http.Header)

CompareAll tests all saved FilterHeader against an http.Header

func (*CompareHeader) String

func (ch *CompareHeader) String() string

String prints key-value (where value is a valid regexp). This method is useful for FlagRegexp

type FilterHeader

type FilterHeader struct {
	Key     string
	Value   string
	ContTot int
	ContHit int
	Rexp    *regexp.Regexp
	sync.Mutex
}

FilterHeader is a struct which keeps key, value (which will be compiled in regexp and how many times key is present in the Header, and how may times regexp is matched

func (*FilterHeader) Compare

func (fh *FilterHeader) Compare(header http.Header, printRegexp bool)

Compare checks a regexp against an header If printRegexp is true, the header value of key is printed. The function is thread-safe

type FlagRegexp

type FlagRegexp struct {
	Rexp *CompareHeader
}

FlagRegexp allows to use struct CompareHeader to create new "bucket" Every "bucket" is made from a value and a regexp

func (*FlagRegexp) Init

func (fr *FlagRegexp) Init()

Init initializes the FlagRegexp struct

func (*FlagRegexp) Set

func (fr *FlagRegexp) Set(srt string) error

Set parse FlagRegexp flag. A flag is defined as "value regexp" and may be used multiple times

func (*FlagRegexp) String

func (fr *FlagRegexp) String() string

String returns all value-regexp in one single string

type FlagUrl

type FlagUrl struct {
	Req *Requests
}

FlagUrl re-define Requests struct to implement flag.Value interface so you can use a FlagUrl struct to parse directly cli param

func (*FlagUrl) Init

func (fu *FlagUrl) Init()

Init initializes the FlagUrl struct

func (*FlagUrl) Set

func (fu *FlagUrl) Set(srt string) error

Set parse urls and puts into Requests struct. If url gives error, url will be skipped Multiple urls may be defined

func (*FlagUrl) String

func (fu *FlagUrl) String() string

String returns all url parsed in one single string

type GeneralCounter

type GeneralCounter struct {
	NumRequest  int
	NumSuccess  int
	NumBadError int
	LongTrans   float64
	ShortTrans  float64
	TotalTime   float64
	TotalByte   float64
	TransTime   []float64
	TotalRun    time.Duration
}

GeneralCounter is a struct which keeps all global stats

func (*GeneralCounter) AddTrans

func (gc *GeneralCounter) AddTrans(time float64)

AddTrans add a transfer time to struct. It's not useful right now, but in future you can use this points to make some graph

func (*GeneralCounter) Results

func (gc *GeneralCounter) Results(parseHeader *CompareHeader)

Results prints all the statistics collected In future this may be handled better (template, refactoring, ..)

type InputRequest

type InputRequest struct {
	Method string
	Url    string
	Header map[string]string
	Body   string
	Hit    int
}

InputRequest represents a parsed url from cli or file

func NewInputRequest

func NewInputRequest(inputURL string) (*InputRequest, error)

NewInputRequest creates a new InputRequest from a url string. The new InputRequest is a basic GET request. The function also modify the input url adding Host and Scheme if not specified. For example google.com becames http://google.com

func NewInputRequestComplex

func NewInputRequestComplex(inputURL, method, body string, header map[string]string) (*InputRequest, error)

NewInputRequestComplex creates a new InputRequest from a url string and set method, body and header It works like NewInputRequest when is creating a InputRequest

type Requests

type Requests struct {
	Reqs       []*InputRequest
	Rand       *rand.Rand
	Cont       int
	MaxRequest int
	sync.Mutex
}

Requests keeps all the InputRequest in one array. Its structure also contains the current-1 object to extract in case of sequential reading, or an object for random number generation in case of random reading

func NewRequests

func NewRequests() *Requests

NewRequests inizialize a Requests object

func (*Requests) AddRequest

func (r *Requests) AddRequest(ir *InputRequest)

AddRequest add to a Requests an InputRequest Don't use NewInputRequest directly as an argument. NewInputRequest may return errors!

func (*Requests) NextUri

func (r *Requests) NextUri(isRandom bool) *InputRequest

NextUri return the next uri to be processed. If isRandom is true, a random url from input is returned, else the next one in order. Pass isRandom as false value is useful if you want to process all the input urls Now NextUri is thread-safe

type SimpleCounter

type SimpleCounter struct {
	QtaBytes   float64
	Elapsed    float64
	StatusCode int
	Path       string
	Header     http.Header
	Error      error
}

SimpleCounter keeps all statistics of a Response

func NewSimpleCounter

func NewSimpleCounter(qtaBytes float64, elapsedTime float64, code int, path string, header http.Header) *SimpleCounter

NewSimpleCounter creates a new SimpleCounter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳