util

package
v0.0.0-...-6b846f9 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const L32 = (^uint64(0) >> 32) << 32

L32 is the leftmost 32 bits set to 1s

View Source
const R32 = ^uint64(0) >> 32

R32 is the rightmost 32 bits set to 1s

Variables

This section is empty.

Functions

func CreateDirectoryIfNotExists

func CreateDirectoryIfNotExists(path string, mode os.FileMode) error

CreateDirectoryIfNotExists creates directory if it doesn't yet exist

func DefaultLogger

func DefaultLogger(debugMode bool, logDir string) (*zap.Logger, error)

DefaultLogger initializing default logger

func Exists

func Exists(path string) bool

Exists checks whether the file exists

func IsTestMode

func IsTestMode() bool

func MapStringKeys

func MapStringKeys(m map[string]interface{}) (keys []string)

MapStringKeys returns a slice of map keys, given that this map is string-indexed

func NewCSPRNG

func NewCSPRNG(nbytes int) ([]byte, error)

NewCSPRNG returns a slice of random bytes

func NewCSPRNGHex

func NewCSPRNGHex(nbytes int) (string, error)

NewCSPRNGHex is a string wrapper for NewCSPRNG

func PackU32s

func PackU32s(a, b uint32) uint64

func PrettyPrint

func PrettyPrint(marshal bool, val interface{})

func ProtectedChangelog

func ProtectedChangelog(allowedFields map[string]bool, before, after interface{}) (diff.Changelog, error)

func StringToSnake

func StringToSnake(s string) string

taken from, with courtesy of: elwinar (https://gist.github.com/elwinar/14e1e897fdbe4d3432e1)

func UnpackU32s

func UnpackU32s(n uint64) (result [2]uint32)

func WriteResponseErrorTo

func WriteResponseErrorTo(w http.ResponseWriter, key string, err error, code int)

WriteResponseErrorTo is a helper function that writes an error to a supplied http.ResponseWriter

Types

type HTTPError

type HTTPError struct {
	Scope   string `json:"scope"`
	Key     string `json:"key"`
	Message string `json:"msg"`
	Code    int    `json:"code"`
}

HTTPError represents a common error wrapper to be used as an HTTP error response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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