util

package
v1.9.12 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanConvert

func CanConvert(data interface{}, optionType types.OptionType) (bool, error)

func ConvertString

func ConvertString(value string, data any, arg string, delimiterFunc types.ListDelimiterFunc) error

func GetSecureString

func GetSecureString(prompt string, w io.Writer, terminal TerminalReader) (string, error)

GetSecureString reads a password from the terminal

func InsertSlice

func InsertSlice[T any](arr []T, pos int, element ...T) []T

InsertSlice inserts item(s) T at position pos and returns a slice

func Min

func Min[T Numeric](x, y T) T

func NewOfType

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

func Reverse

func Reverse[T any](s []T)

Reverse reverses the slice in place

func UnwrapType

func UnwrapType(t reflect.Type) reflect.Type

UnwrapType recursively unwraps pointer.go types and returns the underlying type

func UnwrapValue

func UnwrapValue(v reflect.Value) (reflect.Value, error)

UnwrapValue recursively unwraps pointer and returns the underlying value Returns the zero Value if a nil pointer is encountered

Types

type DefaultTerminal

type DefaultTerminal struct{}

DefaultTerminal implements real terminal operations

func (*DefaultTerminal) IsTerminal

func (t *DefaultTerminal) IsTerminal(fd int) bool

IsTerminal checks if we are attached to a real terminal

func (*DefaultTerminal) ReadPassword

func (t *DefaultTerminal) ReadPassword(fd int) ([]byte, error)

ReadPassword reads a password from the terminal

type Number

type Number struct {
	Int        int64
	Float      float64
	Complex    complex128
	IsInt      bool
	IsFloat    bool
	IsComplex  bool
	IsNegative bool
}

func ParseNumeric

func ParseNumeric(s string) (n Number, ok bool)

type Numeric

type Numeric interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

type TerminalReader

type TerminalReader interface {
	ReadPassword(fd int) ([]byte, error)
	IsTerminal(fd int) bool
}

TerminalReader interface for reading secure input

Jump to

Keyboard shortcuts

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