utils

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInSlice

func IsInSlice(slice []string, match string) bool

IsInSlice checks if a string is in a slice.

func MapToList

func MapToList[T1 comparable, T2 any](m map[T1]T2) []T2

MapToList will change a map to a list.

func Must

func Must[T any](a T, err error) T

Must panics if the passed error is not nil

The purpose of this function is ignoring error checking when writing tests and only tests. This should not be used on production code.

Example (WithError)
// Following line will panic as there is an error
Must("abc", errors.New("an error"))
Output:

Example (WithNoError)
// Following line will not panic as there is no error
result := Must("abc", nil)

// Should print "abc"
fmt.Println(result)
Output:

func RemoveDuplicateFromSlice

func RemoveDuplicateFromSlice[T string | int](sliceList []T) []T

RemoveDuplicateFromSlice removes duplicate values from a slice.

func ToPointer

func ToPointer[T any](t T) *T

ToPointer returns a pointer to the given value.

func ToValue

func ToValue[T any](t *T) T

ToValue returns the value pointed by the given pointer.

func UpperFirstLetter

func UpperFirstLetter(str string) string

UpperFirstLetter returns the given string with the first letter in uppercase.

Types

This section is empty.

Jump to

Keyboard shortcuts

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