generichelper

package
v0.8.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](arr []T, target T) bool

Contains checks if a target item exists in an array of any type.

Example:

names := []string{"Alice", "Bob", "Carol"}
result := Contains(names, "Bob")

Result:

true

func GetJSONTags

func GetJSONTags(v interface{}) []string

GetJSONTags retrieves all JSON tag values from a struct. It returns a slice of JSON tag values extracted from the struct's fields.

Example:

	type Person struct {
  ID        int    `json:"id"`
  Name      string `json:"name"`
  Age       int    `json:"age"`
  CreatedAt string `json:"created_at"`
	}

	p := Person{}
 jsonTags := GetJSONTags(p)

Result:

["id", "name", "age", "created_at"]

func GetMapKeys

func GetMapKeys[K comparable, V any](m map[K]V) []K

GetMapKeys is a generic function that extracts all keys from a map and returns them in a slice.

Example:

ageMap := map[string]int{"Alice": 30, "Bob": 25, "Carol": 27}
keys := GetMapKeys(ageMap)

Result:

["Alice", "Bob", "Carol"]

Types

This section is empty.

Jump to

Keyboard shortcuts

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