goutils

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: MIT Imports: 4 Imported by: 1

README

goutils

Collection of simple Golang helpers

Here is list of simple functions that we usually write again and again in our projects. Such functions don't have any project specific logic and considered to make golang developers' life a bit easier.

Installation

go get -u github.com/Insly/goutils

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateBusinessDaysBetweenDates added in v1.1.5

func CalculateBusinessDaysBetweenDates(from, to time.Time) int

func CopyMap

func CopyMap(input map[string]interface{}) map[string]interface{}

func ElementExists

func ElementExists(slice []interface{}, el interface{}) bool

func ForceBool added in v1.1.1

func ForceBool(list map[string]interface{}, key string, defaultVal bool) bool

func ForceFloat added in v1.1.3

func ForceFloat(list map[string]interface{}, key string, defaultVal float64) float64

func ForceInt added in v1.1.1

func ForceInt(list map[string]interface{}, key string, defaultVal int) int

func ForceString added in v1.1.1

func ForceString(list map[string]interface{}, key string, defaultVal string) string

func GetMapNestedValue added in v1.1.0

func GetMapNestedValue(json map[string]interface{}, nestedKey []string) (val interface{}, ok bool)

func MapToSlice added in v1.1.6

func MapToSlice[key comparable, value any](input map[key]value) []value

MapToSlice extracts map values into a slice

func MergeMaps

func MergeMaps(base, input map[string]interface{}) map[string]interface{}

func MergeNestedMaps added in v1.1.7

func MergeNestedMaps(base, input map[string]interface{}) map[string]interface{}

func MergeSlices

func MergeSlices(base, input []interface{}) []interface{}

func Retry

func Retry(attempts int, sleep time.Duration, f func() error) error

func SliceContainsElement added in v1.1.4

func SliceContainsElement[Element comparable](slice []Element, el Element) bool

SliceContainsElement returns true if the slice contains element el

func SliceContainsElementFunc added in v1.1.4

func SliceContainsElementFunc[Element comparable](slice []Element, comparisonFunc func(el Element) bool) bool

SliceContainsElementFunc returns true if the comparisonFunc for an element returns true

func SliceFilterFunc added in v1.1.4

func SliceFilterFunc[Element comparable](slice []Element, filterFunc func(el Element) bool) []Element

SliceFilterFunc returns new slice which pass the filterFunc

func StructToMap

func StructToMap(input interface{}) (result map[string]interface{}, err error)

func ToBool added in v1.1.1

func ToBool(list map[string]interface{}, key string) *bool

func ToFloat added in v1.1.3

func ToFloat(list map[string]interface{}, key string) *float64

func ToInt added in v1.1.1

func ToInt(list map[string]interface{}, key string) *int

func ToString added in v1.1.1

func ToString(list map[string]interface{}, key string) *string

func UniqueElements added in v1.1.2

func UniqueElements(slice []interface{}) []interface{}

Types

type RetryStop

type RetryStop struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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