util

package
v1.4.527 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DenyNonPublicAddress added in v1.4.516

func DenyNonPublicAddress(_, address string, _ syscall.RawConn) error

DenyNonPublicAddress is a Control function for net.Dialer. The dialer calls it after DNS resolution, with the IP address and the port of the connection. It returns an error if the address is not a public IP address: loopback, private, unique local, link-local, multicast, unspecified, or in nonPublicPrefixes.

func GetAbsolutePath

func GetAbsolutePath(path string) (string, error)

GetAbsolutePath resolves a given path to its absolute form, handling ~, ./, ../, UNC paths, and symlinks.

func GetDefaultConfigPath added in v1.4.256

func GetDefaultConfigPath() (string, error)

GetDefaultConfigPath returns the default path for the configuration file if it exists, otherwise returns an empty string.

func IsSymlinkToDir

func IsSymlinkToDir(path string) bool

Helper function to check if a symlink points to a directory

func NewPublicHTTPClient added in v1.4.516

func NewPublicHTTPClient(timeout time.Duration, control func(network, address string, c syscall.RawConn) error) *http.Client

NewPublicHTTPClient returns an HTTP client for a URL that a template or a request supplies. control is the Control function of the dialer. If control is nil, the client uses DenyNonPublicAddress. The dialer calls control for each connection, thus also for each redirect. A test gives a different function to connect to an httptest server on a loopback address. When DenyNonPublicAddress refuses an address, the error of the client does not include the IP address.

The client stops a request after timeout. It follows a maximum of maxRedirects redirects, and it refuses a redirect to a scheme that is not http or https. The transport refuses these schemes on the first request. The client does not use a proxy, because control must see the address of the server. Each request uses a new connection, thus a client for one request keeps no idle connection.

func ReturnItem

func ReturnItem(item string) string

Types

type GroupItems

type GroupItems[I any] struct {
	Group string
	Items []I
}

func (*GroupItems[I]) ContainsItemBy

func (o *GroupItems[I]) ContainsItemBy(predicate func(item I) bool) (ret bool)

func (*GroupItems[I]) Count

func (o *GroupItems[I]) Count() int

type GroupsItemsSelector

type GroupsItemsSelector[I any] struct {
	SelectionLabel string
	GetItemKey     func(I) string

	GroupsItems []*GroupItems[I]
}

func NewGroupsItemsSelector

func NewGroupsItemsSelector[I any](selectionLabel string,
	getItemLabel func(I) string) *GroupsItemsSelector[I]

func (*GroupsItemsSelector[I]) AddGroupItems

func (o *GroupsItemsSelector[I]) AddGroupItems(group string, items ...I)

func (*GroupsItemsSelector[I]) FindGroupsByItem

func (o *GroupsItemsSelector[I]) FindGroupsByItem(item I) (groups []string)

func (*GroupsItemsSelector[I]) FindGroupsByItemFirst

func (o *GroupsItemsSelector[I]) FindGroupsByItemFirst(item I) (ret string)

func (*GroupsItemsSelector[I]) GetGroupAndItemByItemNumber

func (o *GroupsItemsSelector[I]) GetGroupAndItemByItemNumber(number int) (group string, item I, err error)

func (*GroupsItemsSelector[I]) HasGroup

func (o *GroupsItemsSelector[I]) HasGroup(group string) (ret bool)

func (*GroupsItemsSelector[I]) Print

func (o *GroupsItemsSelector[I]) Print(shellCompleteList bool)

type GroupsItemsSelectorString

type GroupsItemsSelectorString struct {
	*GroupsItemsSelector[string]
}

func NewGroupsItemsSelectorString

func NewGroupsItemsSelectorString(selectionLabel string) *GroupsItemsSelectorString

Jump to

Keyboard shortcuts

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