utils

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2019 License: Apache-2.0 Imports: 21 Imported by: 2

README

GoUtils

Codacy Badge

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteCountIEC

func ByteCountIEC(b int64) string

ByteCountIEC convert the byte in input to MB/KB/TB ecc

func ByteCountSI

func ByteCountSI(b int64) string

ByteCountSI convert the byte in input to MB/KB/TB ecc

func CompareData

func CompareData(data, toFind string) bool

CompareData is Golang wrapper for the C method delegated to verify if the given target is present in the data

func CompareDataInsensitive

func CompareDataInsensitive(data, toFindLower string) bool

CompareDataInsensitive call the C function delegated to 'lowerize' the string and find the first occurence

func CountLine

func CountLine(filename string) int

CountLine return the number of line for a given file using the "wc" shell utils (CPU hungry)

func CreateJSON

func CreateJSON(values ...string) string

CreateJSON is delegated to create a json object for the key pair in input

func ExportMetrics

func ExportMetrics() []byte

ExportMetrics is in charge to retrive the information related to the resources used

func ExtractString

func ExtractString(data *string, first, last string) string

ExtractString is delegated to filter the content of the given data delimited by 'first' and 'last' string

func FilterFromFile

func FilterFromFile(filename string, maxLinesToSearch int, toFilter string, reverse bool) string

FilterFromFile return the text that containt "toFilter" from the file "filename" in a zipped format TODO: Write the method in C using FSEEK instead of line

func FilterFromFileCompress

func FilterFromFileCompress(filename string, maxLinesToSearch int, toFilter string, reverse bool) []byte

FilterFromFileCompress return the text that containt "toFilter" from the file "filename" in a zipped format

func FreeSystemMemory

func FreeSystemMemory(gcSleep *int)

FreeSystemMemory Call the garbage collector every "gcSleep" minutes

func GetFileDate

func GetFileDate(filepath string) string

GetFileDate is delegated to return the date in a string format in which the file was (latest) modified

func GetFileModification

func GetFileModification(filepath string) int64

GetFileModification return the last modification time of the file in input in a UNIX time format

func GetFileSizeC

func GetFileSizeC(filename string) int64

GetFileSizeC wrapper method for retrieve byte lenght of a file

func IsASCII

func IsASCII(s string) bool

IsASCII is delegated to verify if a given string is ASCII compliant

func IsDir

func IsDir(path string) bool

IsDir is delegated to verify that the given path is a directory

func IsFile

func IsFile(path string) bool

IsFile verify if a give filepath is a directory

func IsUpper

func IsUpper(str string) bool

IsUpper verify that a string does not contains upper char

func Join

func Join(strs ...string) string

Join is a quite efficient string concatenator

func JoinArray

func JoinArray(data []string) string

JoinArray concatenate every data in the array and return the string content

func Lz4CompressData

func Lz4CompressData(fileContent string) ([]byte, int)

Lz4CompressData is delegated to compress the input string data using the lz4 algorithm. It return the compressed data itself and the lenght of the compressed data.

func Lz4DecompressData

func Lz4DecompressData(compressedData []byte, l int)

Lz4DecompressData is delegated to extract the previously compressed data

func ParseDate2

func ParseDate2(strdate string) int64

ParseDate2 is an hardcoded parser for date like 31/01/2019 13:29:37,932. Than, return the nanoseceond since Unix epoch

func Random

func Random(min int, max int) int

Random initalizate a new seed using the UNIX Nano time and return an integer between the 2 input value

func ReadAllFile

func ReadAllFile(filePath string) string

ReadAllFile is delegated to read and return all the content of the given file

func ReadAllFileInArray

func ReadAllFileInArray(filePath string) []string

ReadAllFileInArray is delegated to read the file content as tokenize the data by the new line

func ReadFile

func ReadFile(filename string, lines int) []byte

ReadFile is in charge to read the last number of lines for a given file and return the content in a compressed format

func ReadFileContentC

func ReadFileContentC(filename string) string

ReadFileContentC wrapper method for retrieve content by a file

func ReadFilePath

func ReadFilePath(path string) []string

ReadFilePath is delegated to filter every (sub)file path from a given directory

func RecognizeFormat

func RecognizeFormat(input string) (string, string)

RecognizeFormat is delegated to valutate the extension and return the properly Mimetype by a given format type reurn: (Mimetype http compliant,Content-Disposition header value)

func RemoveElement

func RemoveElement(data []string, j []int) []string

RemoveElement delete the element of the indexes contained in j of the data in input

func RemoveFromString

func RemoveFromString(s []byte, i int) []byte

RemoveFromString Remove a given element from a string

func RemoveWhiteSpaceArray

func RemoveWhiteSpaceArray(data []string) []string

RemoveWhiteSpaceArray is delegated to iterate every array row and remove the whitespace from the given string

func RemoveWhiteSpaceString

func RemoveWhiteSpaceString(str string) string

RemoveWhiteSpaceString is delegated to remove the whitespace from the given string

func RetrieveLines

func RetrieveLines(fileContet string) int

RetrieveLines return the number of lines in the given string

func SecureRequest

func SecureRequest(ctx *fasthttp.RequestCtx, ssl bool)

SecureRequest is delegate to set the necessary secure headers NOTE: CORS is set to '*', be sure to rewrite the headers when expose the application

func SetDebugLevel

func SetDebugLevel(level string) log.Level

SetDebugLevel return the LogRus object by the given string

func SpellCheck

func SpellCheck(filepath, wrongword string) string

SpellCheck is a Go wrapper for the C spell check algorithm

func SplitStringInArray

func SplitStringInArray(data string) []string

SplitStringInArray is delegated to split the string by the new line

func StartCPUProfiler

func StartCPUProfiler(file *os.File)

StartCPUProfiler Save the cpu profile information into the given file NOTE: Remember to defer pprof.StopCPUProfile() after the function

func ValidateInjection

func ValidateInjection(payload string, mustContain []string) bool

ValidateInjection provide commons methods for validate a given payload

func VerifyCert

func VerifyCert(filePath, pub, priv string) bool

VerifyCert is delegated to verify that the given public and private cert exist in the filepath

func VerifyFilesExists

func VerifyFilesExists(filePath string, files []string) bool

VerifyFilesExists is delegated to verify that the given list of file exist in the directory

func VerifyIfPresent

func VerifyIfPresent(content string, entryList []string) bool

VerifyIfPresent Verify if a given string is present in the list

Types

type Monitor

type Monitor struct {
	Alloc,
	TotalAlloc,
	Sys,
	Mallocs,
	Frees,
	LiveObjects,
	PauseTotalNs,
	MCacheInuse uint64
	GCCPUFraction float64
	NumGC         uint32
	NumGoroutine  int
}

Monitor is the data structure for store the metrics data

Jump to

Keyboard shortcuts

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