util

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: MIT Imports: 16 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checksum added in v1.1.1

func Checksum(a string) string

Checksum creates a unique CRC32 checksum from a string

func ElapsedTimeSince

func ElapsedTimeSince(t time.Time) int64

ElapsedTimeSince returns the difference between t and now.

func Fingerprint

func Fingerprint(a string) string

Fingerprint creates a unique ID (MD5) from a string

func GetJSON

func GetJSON(url string, target interface{}) error

GetJSON querys a url for an expected JSON struct

func IncT

func IncT(t int64, m int) int64

IncT increments a timstamp (in seconds) by m minutes.

func PostJSON

func PostJSON(url string, body interface{}, response interface{}) error

PostJSON posts a JSON object to a given URL

func PrettyPrintJSON

func PrettyPrintJSON(target interface{})

PrettyPrintJSON prints a struct to STDOUT nicely

func PrintJSON

func PrintJSON(target interface{}) string

PrintJSON formats a struct into a JSON string

func PutJSON

func PutJSON(url string, target interface{}) error

PutJSON posts a JSON object to a given URL (HTTP PUT)

func Random

func Random(max int) int

Random returns a random number between 0 .. max

func RandomPlusMinus

func RandomPlusMinus(max int) int

RandomPlusMinus returns a random number between -max .. max

func RandomToken

func RandomToken(prefix string) (string, error)

RandomToken generates a random token similar to a to a RFC 4122 UID

func RequestLogger

func RequestLogger() gin.HandlerFunc

RequestLogger is used to print the GIN raw request message body

func ShortUUID

func ShortUUID() (string, error)

ShortUUID returns a short (6 bytes) UID

func SimpleUUID

func SimpleUUID() (string, error)

SimpleUUID generates a random UUID according to RFC 4122, without any dashes

func StringToTime

func StringToTime(format, t string) int64

StringToTime converts a string with a date/time into a timestamp

func Timestamp

func Timestamp() int64

Timestamp returns the curent time in seconds UTC

func TimestampNano

func TimestampNano() int64

TimestampNano returns the curent time in miliseconds UTC

func TimestampToHour

func TimestampToHour(t int64) int

TimestampToHour retuns the hour of the day for the timestamp

func TimestampToUTC

func TimestampToUTC(t int64) string

TimestampToUTC converts a timestamp to UTC timestamp

func TimestampToWeekday

func TimestampToWeekday(t int64) int

TimestampToWeekday retuns the day of the week for the timestamp

func UUID

func UUID() (string, error)

UUID generates a random UUID according to RFC 4122

func ValueWithDefault

func ValueWithDefault(value, def string) string

ValueWithDefault returns the value of a default if empty

Types

This section is empty.

Jump to

Keyboard shortcuts

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