utils

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package utils provides utility functions for handling common tasks such as setting default values, checking emptiness, and normalizing map keys. Includes string comparison functions and map merging functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsLower

func ContainsLower(a, b string) bool

ContainsLower checks if string 'a' contains string 'b' case-insensitively.

func DeepMergeMapsWithoutOverwrite

func DeepMergeMapsWithoutOverwrite(first, second map[string]any)

DeepMergeMapsWithoutOverwrite merges two maps of map[string]any, adding values from second to first without overwriting the existing values in first. It performs a deep merge, handling nested maps recursively.

func EqualLower

func EqualLower(a, b string) bool

Equal compares two strings case-insensitively and returns true if they are equal.

func IsEmpty

func IsEmpty[S comparable](input S) bool

IsEmpty checks if the input value is empty. S must be a comparable type.

func IsURL

func IsURL(str string) bool

IsURL checks if the input string is a valid URL.

func NormalizeMap

func NormalizeMap(m map[string]any) map[string]any

NormalizeMap normalizes the keys of a map to title case recursively. If the value is another map, it will recursively normalize its keys as well.

func SetIfEmpty

func SetIfEmpty[S comparable](input *S, value S)

SetIfEmpty sets the value of input to the specified value if it is empty. S must be a comparable type.

func SetMapIfNil

func SetMapIfNil[M ~map[K]V, K comparable, V any](input *M, values M)

SetMapIfNil sets the value of input to the provided defaultMap if input is nil. M is constrained to maps with keys of type K and values of type V.

func SetSliceIfNil

func SetSliceIfNil[S ~[]T, T any](input *S, values ...T)

SetSliceIfNil sets the value of input to the provided values slice if input is nil. S is constrained to slices of any type T.

Types

This section is empty.

Jump to

Keyboard shortcuts

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