utils

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const Authorization string = "Authorization"

Authorization for header key

View Source
const CacheControl string = "Cache-Control"

CacheControl for header key

View Source
const CacheControlMustRevalidate string = "must-revalidate, post-check=0, pre-check=0"

CacheControlMustRevalidate for header key

View Source
const Connection string = "Connection"

Connection for header key

View Source
const ContentDescription string = "Content-Description"

ContentDescription for header key

View Source
const ContentDisposition string = "Content-Disposition"

ContentDisposition for header key

View Source
const ContentLength string = "Content-Length"

ContentLength for header key

View Source
const ContentTransferEncoding string = "Content-Transfer-Encoding"

ContentTransferEncoding for header key

View Source
const ContentType string = "Content-Type"

ContentType for header key

View Source
const Expires string = "Expires"

Expires for header key

View Source
const JSONApplication string = "application/json"

JSONApplication for Content-Type headers

View Source
const JSONApplicationUTF8 string = JSONApplication + "; charset=UTF-8"

JSONApplicationUTF8 for Content-Type headers, UTF charset

View Source
const KeepAlive string = "Keep-Alive"

KeepAlive for Connection headers

View Source
const OctetStream string = "application/octet-stream"

OctetStream for Content-Type headers

View Source
const OsctrlUserAgent string = "osctrl-http-client/1.1"

OsctrlUserAgent for customized User-Agent

View Source
const Pragma string = "Pragma"

Pragma for header key

View Source
const PragmaPublic string = "public"

PragmaPublic for header key

View Source
const TextPlain string = "text/plain"

TextPlain for Content-Type headers

View Source
const TextPlainUTF8 string = TextPlain + "; charset=UTF-8"

TextPlainUTF8 for Content-Type headers, UTF charset

View Source
const TransferEncodingBinary string = "binary"

TransferEncodingBinary for header key

View Source
const UserAgent string = "User-Agent"

UserAgent for header key

View Source
const XForwardedFor string = "X-Forwarded-For"
View Source
const XRealIP string = "X-Real-IP"

XRealIP for header key

Variables

View Source
var (
	// OneMinute - 60 seconds
	OneMinute = 60 * time.Second
	// OneHour - 3600 seconds
	OneHour = 60 * time.Minute
	// SixHours - 21600 seconds
	SixHours = 6 * time.Hour
	// OneDay - 86400 seconds
	OneDay = 24 * time.Hour
	// FifteenDays - 1296000 seconds
	FifteenDays = 15 * OneDay
)

Functions

func BytesReceivedConversion

func BytesReceivedConversion(b int) string

BytesReceivedConversion - Helper to format bytes received into KB, MB, TB... Binary format

func CheckUUID

func CheckUUID(s string) bool

CheckUUID - Helper to check if a string is a valid UUID

func Contains added in v0.4.7

func Contains(all []string, target string) bool

Contains checks if string is in the slice

func DebugHTTP

func DebugHTTP(r *http.Request, showBody bool) string

DebugHTTP - Helper for debugging purposes and dump a full HTTP request

func DebugHTTPDump

func DebugHTTPDump(l *zerolog.Logger, r *http.Request, showBody bool)

DebugHTTPDump - Helper for debugging purposes and dump a full HTTP request

func DurationSeconds

func DurationSeconds(duration time.Duration) int

DurationSeconds - Helper to get the seconds value fom a Duration

func GenKSUID

func GenKSUID() string

GenKSUID - Helper to generate a KSUID See https://github.com/segmentio/ksuid for more info about KSUIDs

func GenRandomString

func GenRandomString(n int) string

GenRandomString - Helper to generate a random string of n characters

func GenUUID

func GenUUID() string

GenUUID - Helper to generate a UUID See https://github.com/google/uuid for more info about UUIDs

func GetIP

func GetIP(r *http.Request) string

GetIP - Helper to get the IP address from a HTTP request

func HTTPDownload

func HTTPDownload(w http.ResponseWriter, description, filename string, filesize int64)

HTTPDownload - Helper to send HTTP response with a file

func HTTPResponse

func HTTPResponse(w http.ResponseWriter, cType string, code int, data interface{})

HTTPResponse - Helper to send HTTP response

func InFutureTime

func InFutureTime(t time.Time) string

InFutureTime - Helper to format future times only returning one value (minute, hour, day)

func Intersect

func Intersect(slice1, slice2 []uint) []uint

Intersect returns the intersection of two slices of uints

func PastFutureTimes

func PastFutureTimes(t time.Time) string

PastFutureTimes - Helper to format past or future times

func PastFutureTimesEpoch

func PastFutureTimesEpoch(ts int64) string

PastFutureTimesEpoch - Helper to format past or future times

func PastTimeAgo

func PastTimeAgo(t time.Time) string

PastTimeAgo - Helper to format past times only returning one value (minute, hour, day)

func RandomForNames

func RandomForNames() string

Helper to generate a random MD5 to be used with queries/carves

func SendRequest

func SendRequest(reqType, reqURL string, params io.Reader, headers map[string]string) (int, []byte, error)

SendRequest - Helper function to send HTTP requests

func StringToBoolean

func StringToBoolean(s string) bool

StringToBoolean - Helper to convert a string into boolean

func StringToInteger

func StringToInteger(s string) int64

StringToInteger - Helper to convert a string into integer

func StringifyTime

func StringifyTime(seconds int) string

StringifyTime - Helper to get a string based on the difference of two times

func TimeTimestamp

func TimeTimestamp(t time.Time) string

TimeTimestamp - Helper to format times in timestamp format

Types

This section is empty.

Jump to

Keyboard shortcuts

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