utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAValidNetAddress             = errors.New(`address is not valid`)
	ErrEmptyOrInvalidForwardedHeader   = errors.New(`empty or invalid forwarded header`)
	ErrUnableToGetIPFromSpecialHeaders = errors.New(`unable to get ip from special headers`)
)

Functions

func AnyEvilCharacter

func AnyEvilCharacter(phrase string) bool

AnyEvilCharacter any character in the switch below will return true on 1st find. Source: https://github.com/dinoex/iroffer-dinoex/blob/master/src/dinoex_utilities.c#L555

func ChecksumCRC32

func ChecksumCRC32(reader io.Reader) (checksum string, err error)

ChecksumCRC32 returns a crc32 hash from the specified reader

func ChunkBy

func ChunkBy[T any](items []T, chunkSize int) (chunks [][]T)

func DurationToSeconds

func DurationToSeconds(duration string) (seconds float64)

func GetUserAgent

func GetUserAgent() string

GetUserAgent returns a random user agent from the private pre-defined user agent array.

func IsEmpty

func IsEmpty(in any) bool

func LowerCaseRemoveSpecial

func LowerCaseRemoveSpecial(phrase string) string

LowerCaseRemoveSpecial removes special characters from a string, while converting the letters to lowercase.

func MergeChan

func MergeChan[N any](cs ...<-chan N) <-chan N

MergeChan merges all the channels and outputs them into one, following the Fan-In Fan-Out pattern.

func NewIdentifier

func NewIdentifier() string

func NumericQuality

func NumericQuality(quality string) (numeric int)

func Ordinal

func Ordinal(x int) string

func ParseIP

func ParseIP(s string) (ip net.IP)

ParseIP is a wrapper on top of the net.ParseIP along with octal parsing.

func PointerOf

func PointerOf[T any](t T) *T

func RabinKarp

func RabinKarp(phrase string, patterns []string) int

RabinKarp searches given patterns in phrase and returns the number of matched ones. Returns a zero is there are no matches.

func RealRemoteAddr

func RealRemoteAddr(r *http.Request) (host, port string, err error)

RealRemoteAddr first attempts to retrieve the address from the 'X-Forwarded-For' if that fails, it attempts to retrieve from the special headers.

func RemoveEvilCharacters

func RemoveEvilCharacters(phrase string, replaceSpaces ...bool) string

RemoveEvilCharacters strips special characters by replacing them with underscores. Source: https://github.com/dinoex/iroffer-dinoex/blob/master/src/dinoex_utilities.c#L555

func SecondsToDuration

func SecondsToDuration(seconds float64) string

func SetUserAgent

func SetUserAgent(req *http.Request)

func SurroundWith

func SurroundWith(with rune, strs ...string) string

func TillEndOfDay

func TillEndOfDay() time.Duration

TillEndOfDay returns the time duration for UTC till we reach end of day.

func TryCast

func TryCast[T any](s interface{}) (T, error)

func Unpad

func Unpad(phrase string) (out string)

func ValueOf

func ValueOf[T any](t *T) (v T)

Types

This section is empty.

Jump to

Keyboard shortcuts

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