utils

package module
v0.0.0-...-0ced705 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: MIT Imports: 14 Imported by: 0

README

Small helpers I end up needing in almost all go based services

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(v bool) *bool

func Compress

func Compress(in io.Reader, out io.Writer) error

Get bytes provided in `in`, compressed in `out` Uses: "github.com/klauspost/compress/zstd"

func Decompress

func Decompress(in io.Reader, out io.Writer) error

Provide bytes pre-compressed using zstd in `in` and get them decompressed in `out` Uses: "github.com/klauspost/compress/zstd"

func Float32Ptr

func Float32Ptr(f float32) *float32

func Float64Ptr

func Float64Ptr(f float64) *float64

func GenHash128a

func GenHash128a(txt []byte) string

Generates a fnv 128 hash

func GenHash64a

func GenHash64a(txt []byte) string

Generates a fnv 64 hash

func GetInt64

func GetInt64(v interface{}) (int64, bool)

Get an int64 from any integer parading as an interface

func Int16Ptr

func Int16Ptr(i int16) *int16

func Int32Ptr

func Int32Ptr(i int32) *int32

func Int64Ptr

func Int64Ptr(i int64) *int64

func Int8Ptr

func Int8Ptr(i int8) *int8

func IntPtr

func IntPtr(i int) *int

func PartialObfuscate

func PartialObfuscate(s string) string

Obfuscates email IDs, phones, names

func RandomFromBytes

func RandomFromBytes(n int, letters []byte) string

Generates a random string of length `n` from characters given in `letters`

func RandomNumbers

func RandomNumbers(n int) string

Generates a string of length `n` consisting only of characters [0-9]

func RandomString

func RandomString(n int) string

Generates a random string of length `n` consisting of characters [a-z]

func StringPtr

func StringPtr(s string) *string

func TimeHash128a

func TimeHash128a() string

Generates 128 fnv hash of time.Now().UnixNano()

func TimeHash64a

func TimeHash64a() string

Generates fnv 64 hash of time.Now().UnixNano()

func TrimStruct

func TrimStruct(v reflect.Value)

Trims all string type and values in string pointer in a struct. Given a struct `s` - accepts reflect.Value(&s)

func ULID

func ULID() string

Generates a ULID as described at: "github.com/oklog/ulid/v2" Panics on failure

func UUID

func UUID() string

Returns a UUID v4 string Panics if failed to generate. Uses `github.com/google/uuid`

func Uint16Ptr

func Uint16Ptr(u uint16) *uint16

func Uint32Ptr

func Uint32Ptr(u uint32) *uint32

func Uint64Ptr

func Uint64Ptr(u uint64) *uint64

func Uint8Ptr

func Uint8Ptr(u uint8) *uint8

func UintPtr

func UintPtr(u uint) *uint

func WrapErr

func WrapErr(err error, msgs ...string) error

Wraps the given error string with a prefix of Function Name -> [msgs[0] -> msgs[1] -> ... msgs[i]] -> err

func XSSSanitizeStruct

func XSSSanitizeStruct(v reflect.Value)

Sanitizes all string and string pointer types in a struct for XSS Given any struct `s` - accepts reflect.Value(&s)

Types

This section is empty.

Jump to

Keyboard shortcuts

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