utils

package
v0.0.0-...-841f565 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

README

*utils

You might be wondering why these utils have sub folders for different types of utilities. Why not just create a crypto library instead of cryptoutils.

Golang's standard library already has a crypto package. When you import something like. import "crypto" the package names collide and you're forced to give your package an alias like cryptoutils anyway.

import (
    "crypto"
    cryptoutils "my/crypto"
)

So, I've adopted a standard of simply defining my packages with hopefully unique names. Then their import statements look much cleaner.

import (
    "crypto"
    "my/cryptoutils"
)

If I need to refactor a package I simply use the Jetbrains refactor features to move things around ane ensure all internal usage of those libraries are covered.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(username, password string) string

func BuildDeepMapString

func BuildDeepMapString(val interface{}, keys []string, level map[string]interface{})

BuildDeepMapString uses a slice of keys to build an n dimensional map[string]interface{} Be aware, providing an empty keys slice will result in a noop function

func BytesToString

func BytesToString(data []byte) string

func CheckErrFatal

func CheckErrFatal(err error, message string)

CheckErrFatal

func DecodeStringToBytes

func DecodeStringToBytes(data, format string) ([]byte, error)

func EncodeBytesToString

func EncodeBytesToString(data []byte, format string) (string, error)

func EnvLookup

func EnvLookup(key, defaultValue string) string

EnvLookup looks up env vars, returns default string if not found

func EnvLookupAll

func EnvLookupAll() map[string]string

EnvLookupAll returns a map[string]string of all environment variables

func ExpandEnvOnArgs

func ExpandEnvOnArgs(args []string) []string

ExpandEnvOnArgs expands environmental variables from all strings in the arg list

func GetFreePort

func GetFreePort() (string, error)

GetFreePort attempts to resolve localhost:0 *nix operating systems will return an unused port instead of resolving port 0

func GetRuntime

func GetRuntime() map[string]string

GetRuntime returns runtime info as a map[string]string

func ISODateNow

func ISODateNow() string

func IsK8sContextSafe

func IsK8sContextSafe(defaultContexts []string, envKey, currentContext string) bool

IsK8sContextSafe return a slice of k8s safe contexts

func JoinStrings

func JoinStrings(separator string, stringValues ...string) string

func MapToEnvStringSlice

func MapToEnvStringSlice(env map[string]string) []string

MapToEnvStringSlice converts a map of environmental variables to a string slice of kv pairs Useful for interfaces that require this data structure like docker

func MarshalJSON

func MarshalJSON(obj interface{}, explode bool) (string, error)

func MarshalJSONSafe

func MarshalJSONSafe(obj interface{}, explode bool) string

func MergeMaps

func MergeMaps(maps ...map[string]interface{}) map[string]interface{}

MergeMaps merges n number of maps[string]interface

func StringToBytes

func StringToBytes(data string) []byte

func UUIDV4

func UUIDV4() string

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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