commons

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package commons is for utilities not related to business logic (files, debug, collections, etc)

Index

Constants

This section is empty.

Variables

View Source
var (
	// IsDebugEnabled is true when the DEBUG env var is not empty.
	IsDebugEnabled = os.Getenv("DEBUG") != ""
)

Functions

func All

func All(vs []string, f func(string) bool) bool

All returns true if all of the strings in the slice satisfy the predicate f.

func Any

func Any(vs []string, f func(string) bool) bool

Any returns true if one of the strings in the slice satisfies the predicate f.

func Contains

func Contains(vs []string, t string) bool

Contains returns true if the target string t is in the slice.

func Debug

func Debug(message string)

Debug prints message when debug mode is enabled.

func Debugf

func Debugf(message string, args ...interface{})

Debugf prints message when debug mode is enabled. Substitutes format with provided arguments. Works like fmt.Sprintf.

func FillTemplate

func FillTemplate(templatePath, finalPath string, mapping map[string]string) error

FillTemplate fills source template from file and stores it under provided destination. To fill the template provided map with mappings is used.

func Filter

func Filter(vs []string, f func(string) bool) []string

Filter returns a new slice containing all strings in the slice that satisfy the predicate f.

func Include

func Include(vs []string, t string) bool

Include returns true if the target string t is in the slice.

func Index

func Index(vs []string, t string) int

Index returns the first index of the target string t, or -1 if no match is found.

func LazyDebug

func LazyDebug(getMsgFn MessageProvider)

LazyDebug should be used when message construction is heavy and should be executed only when debug is enabled

func MakeDir

func MakeDir(path string) error

MakeDir creates directory under a given path.

func Map

func Map(vs []string, f func(string) string) []string

Map returns a new slice containing the results of applying the function f to each string in the original slice.

func RemoveIndex

func RemoveIndex(s []string, index int) []string

RemoveIndex removes the element from the slice by its index.

func RemoveLast

func RemoveLast(s []string) []string

RemoveLast removes the last element from the slice and returns the altered slice.

func SortKeys

func SortKeys(m map[string]interface{}) []string

SortKeys sorts keys of the map of interfaces and returns them in the slice.

func SortMapKeys

func SortMapKeys(m map[string]string) []string

SortMapKeys sorts keys of the map of strings and returns them in the slice.

func WriteToJSONFile added in v1.1.0

func WriteToJSONFile(content interface{}, fileName string) error

WriteToJSONFile marshalls provided content to json and stores it in file with provided name.

Types

type MessageProvider

type MessageProvider func() string

MessageProvider allows for definition of MessageProvider that will be invoked in order to obtain the message before logging it.

Directories

Path Synopsis
Package cli is for common CLI utilities
Package cli is for common CLI utilities
Package testassist holds testing helpers
Package testassist holds testing helpers

Jump to

Keyboard shortcuts

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