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
- func ByteSize(b float64) string
- func ParseAllInputFile(fileName string, request *Requests)
- func ProcessData(dataChannel chan *SimpleCounter, HC *CompareHeader, waitGroup *sync.WaitGroup)
- type CompareHeader
- type FilterHeader
- type FlagRegexp
- type FlagUrl
- type GeneralCounter
- type InputRequest
- type Requests
- type SimpleCounter
Constants ¶
const ( KB float64 = 1 << (10 * iota) MB GB TB )
Define some useful constants
const (
ErrorFormat = "Formatting error"
)
Error constant
Variables ¶
This section is empty.
Functions ¶
func ParseAllInputFile ¶
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
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) 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
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 ¶
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 ¶
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 (*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