structx

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultValue added in v0.1.3

func GetDefaultValue[T any](data map[string]any, key string, defaultValue T) T

GetDefaultValue returns the default value if the key is not found in the data Example: GetDefaultValue(data, "headless", false)

func NewInstance added in v0.1.3

func NewInstance[T any]() T

NewInstance create an instance of the given type T. the main purpose of this function is to create an instance of a type, can handle the type of T is a pointer or not. eg. NewInstance[int] returns 0. eg. NewInstance[*int] returns *0 (will be ptr of 0, not nil!).

func PtrOf added in v0.1.3

func PtrOf[T any](v T) *T

PtrOf returns a pointer of T. useful when you want to get a pointer of a value, in some config, for example. eg. PtrOf[int] returns *int. eg. PtrOf[*int] returns **int.

func Reverse added in v0.1.3

func Reverse[S ~[]E, E any](s S) S

Reverse returns a new slice with elements in reversed order.

func Set

func Set[T comparable]() *set[T]

Set ...

func ToOptional added in v0.1.3

func ToOptional[T any](value any) *T

func ToSliceOfInt added in v0.1.3

func ToSliceOfInt(input any) ([]int, error)

func ToStringMap added in v0.1.3

func ToStringMap(inputMap map[string]any) map[string]string

ToStringMap converts a map[string]any to map[string]string. It iterates through the input map and includes only the key-value pairs where the value is of type string.

func TypeOf added in v0.1.3

func TypeOf[T any]() reflect.Type

TypeOf returns the type of T. eg. TypeOf[int] returns reflect.TypeOf(int). eg. TypeOf[*int] returns reflect.TypeOf(*int).

Types

type Pair added in v0.1.3

type Pair[F, S any] struct {
	First  F
	Second S
}

Jump to

Keyboard shortcuts

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