utils

package
v1.95.2 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Daytime of the night
	Daytime port = 13
	// FTP protocol port number
	FTP port = 21
	// SSH protocol port number
	SSH port = 22
	// Telnet protocol port number
	Telnet port = 23
	// SMTP protocol port number
	SMTP port = 25
	// Time protocol port number
	Time port = 37
	// Whois protocol port number
	Whois port = 43
	// DNS protocol port number
	DNS port = 53
	// TFTP protocol port number
	TFTP port = 69
	// Gopher protocol port number
	Gopher port = 70
	// HTTP protocol port number
	HTTP port = 80
	// Kerberos protocol port number
	Kerberos port = 88
	// Nic protocol port number
	Nic port = 101
	// SFTP protocol port number
	SFTP port = 115
	// NTP protocol port number
	NTP port = 123
	// IMAP protocol port number
	IMAP port = 143
	// SNMP protocol port number
	SNMP port = 161
	// IRC protocol port number
	IRC port = 194
	// HTTPS protocol port number
	HTTPS port = 443
	// Docker protocol port number
	Docker port = 2376
	// RDP protocol port number
	RDP port = 3389
	// Minecraft protocol port number
	Minecraft port = 25565
)
View Source
const (
	EmptyIPAddressVisualization = "-"
)

Variables

View Source
var (
	// utils.AllZones represents the list of known Exoscale zones, in case we need it without performing API lookup.
	AllZones = []string{
		string(v3.ZoneNameATVie1),
		string(v3.ZoneNameATVie2),
		string(v3.ZoneNameBGSof1),
		string(v3.ZoneNameCHDk2),
		string(v3.ZoneNameCHGva2),
		string(v3.ZoneNameDEFra1),
		string(v3.ZoneNameDEMuc1),
		string(v3.ZoneNameHrZag1),
	}
)

Functions

func AllZonesV3 added in v1.85.3

func AllZonesV3(ctx context.Context, client *v3.Client, zoneName v3.ZoneName) ([]v3.Zone, error)

func AskQuestion added in v1.85.0

func AskQuestion(ctx context.Context, text string) bool

func DatePtrFormatOutput added in v1.85.0

func DatePtrFormatOutput(t *time.Time) string

func DecorateAsyncOperation added in v1.85.0

func DecorateAsyncOperation(message string, fn func())

utils.DecorateAsyncOperation is a cosmetic helper intended for wrapping long asynchronous operations, outputting progress feedback to the user's terminal. TODO remove this one once all has been migrated to utils.DecorateAsyncOperation.

func DecorateAsyncOperations added in v1.85.0

func DecorateAsyncOperations(message string, fns ...func() error) error

func DefaultBool added in v1.65.0

func DefaultBool(b *bool, def bool) bool

DefaultBool returns the value of the bool pointer b if not nil, otherwise the default value specified.

func DefaultIP added in v1.65.0

func DefaultIP(i any, def string) string

DefaultIP returns the IP as string if not nil, otherwise the default value specified. Accepts either *net.IP, net.IP, or string.

func DefaultInt64 added in v1.65.0

func DefaultInt64(i *int64, def int64) int64

DefaultInt64 returns the value of the int64 pointer b if not nil, otherwise the default value specified.

func DefaultString added in v1.65.0

func DefaultString(s *string, def string) string

DefaultString returns the value of the string pointer s if not nil, otherwise the default value specified.

func EllipString added in v1.65.0

func EllipString(s string, maxLen int) string

EllipString truncates the string s with an ellipsis character if longer than maxLen.

func ForEveryZone added in v1.81.0

func ForEveryZone(zones []v3.Zone, f func(zone v3.Zone) error) error

ForEveryZone executes the function f for every specified zone, and returns a multierror.Error containing all errors that may have occurred during execution.

func ForEveryZoneAsync added in v1.95.0

func ForEveryZoneAsync(
	ctx context.Context,
	zones []v3.Zone,
	timeout time.Duration,
	sink *WarningSink,
	showSpinner bool,
	f func(ctx context.Context, zone v3.Zone) error,
) int

ForEveryZoneAsync runs f concurrently per zone with a per-zone timeout derived from ctx. Per-zone errors are buffered into sink as warnings and never abort the other zones. Returns the number of zones that failed.

If showSpinner is true, a single rotating glyph is drawn on stderr for the full duration of the fanout (until every zone has either returned or timed out). Silent on non-TTY stderr and under globalstate.Quiet, so callers can pass true unconditionally.

func GetInstancesAttachedToEIP added in v1.66.0

func GetInstancesAttachedToEIP(ctx context.Context, client *v3.Client, elasticIPID string) ([]v3.ListInstancesResponseInstances, error)

func GetSettingBool added in v1.84.0

func GetSettingBool(settings map[string]interface{}, key string) bool

GetSettingBool safely retrieves a bool value from settings map

func GetSettingFloat64 added in v1.84.0

func GetSettingFloat64(settings map[string]interface{}, key string) int

GetSettingFloat64 safely retrieves a float64 value from settings map and converts to int

func GetSettingString added in v1.84.0

func GetSettingString(settings map[string]interface{}, key string) string

GetSettingString safely retrieves a string value from settings map

func Int64PtrFormatOutput added in v1.85.0

func Int64PtrFormatOutput(n *int64) string

func IsEmptyStringPtr added in v1.65.0

func IsEmptyStringPtr(s *string) bool

func IsInList added in v1.65.0

func IsInList(list []string, v string) bool

IsInList returns true if v exists in the specified list, false otherwise.

func NonEmptyStringPtr added in v1.65.0

func NonEmptyStringPtr(s string) *string

NonEmptyStringPtr returns a non-nil pointer to s if the string is not empty, otherwise nil.

func ParseInstanceType added in v1.78.5

func ParseInstanceType(instanceType string) v3.InstanceType

ParseInstanceType returns an v3.InstanceType with family and name.

func PrintOutput added in v1.85.0

func PrintOutput(o output.Outputter, err error) error

output prints an outputter interface to the terminal, formatted according to the global format specified as CLI flag.

func RandStringBytes

func RandStringBytes(n int) (string, error)

RandStringBytes Generate random string of n bytes

func ReadInput added in v1.85.2

func ReadInput(ctx context.Context, reader *bufio.Reader, text, def string) (string, error)

func RunAsync added in v1.88.0

func RunAsync(ctx context.Context, client *v3.Client, message string, f func(context.Context, *v3.Client) (*v3.Operation, error)) (err error)

RunAsync decorates and waits for an async operation till success.

func SliceToMap added in v1.65.0

func SliceToMap(v []string) (map[string]string, error)

SliceToMap returns a map[string]string from a slice of KEY=VALUE formatted strings. This function is used to obtain a map[string]string from CLI flags, as the current CLI flags parsing module used (github.com/spf13/pflag) implements a "StringToString" type flag but doesn't support passing empty values, which we need in some cases (e.g. resetting labels).

func StrPtrFormatOutput added in v1.85.0

func StrPtrFormatOutput(s *string) string

func VersionIsNewer added in v1.65.0

func VersionIsNewer(old, new string) bool

VersionIsNewer returns true if new version has potential deprecation

func VersionMajor added in v1.65.0

func VersionMajor(version string) uint32

VersionMajor returns major part of a version number (given "x.y(.z)", returns "x"). If the input version is not in semver format, returns 0.

func VersionMinor added in v1.65.0

func VersionMinor(version string) uint32

VersionMinor returns minor part of a version number (given "x.y(.z)", returns "y"). If the input version is not in semver format, returns 0.

func VersionsAreEquivalent added in v1.65.0

func VersionsAreEquivalent(a, b string) bool

VersionsAreEquivalent returns true if new and old versions both have same major and minor numbers

Types

type Spinner added in v1.95.0

type Spinner struct {
	// contains filtered or unexported fields
}

Spinner draws a single rotating glyph at column 0 of stderr until Stop is called. By design the spinner occupies exactly one character, so concurrent writes to stdout (which start at column 0 after a newline) cleanly overwrite the glyph — no caption ghosts past the leading '│' of a streamed table row.

Silent if stderr isn't a TTY or globalstate.Quiet is on, so callers can use Start/Stop unconditionally.

func NewSpinner added in v1.95.0

func NewSpinner() *Spinner

func (*Spinner) SetWriter added in v1.95.0

func (s *Spinner) SetWriter(w io.Writer)

SetWriter overrides the writer the spinner draws on. Must be called before Start. If w is not an *os.File pointing at a TTY, Start is a no-op.

func (*Spinner) Start added in v1.95.0

func (s *Spinner) Start()

func (*Spinner) Stop added in v1.95.0

func (s *Spinner) Stop()

Stop erases the glyph and returns once the drawing goroutine has exited. Safe to call multiple times and safe to call when Start was a no-op.

type WarningSink added in v1.95.0

type WarningSink struct {
	// contains filtered or unexported fields
}

WarningSink buffers per-zone warnings so they don't interleave with streamed stdout output. Flush is called explicitly (via defer) at the end of the command, or implicitly on SIGINT/SIGTERM via InstallSignalFlush.

func NewWarningSink added in v1.95.0

func NewWarningSink() *WarningSink

NewWarningSink returns a sink that writes to os.Stderr on Flush.

func NewWarningSinkTo added in v1.95.0

func NewWarningSinkTo(w io.Writer) *WarningSink

NewWarningSinkTo returns a sink that writes to w on Flush. Used in tests.

func (*WarningSink) Add added in v1.95.0

func (s *WarningSink) Add(format string, args ...any)

Add buffers a formatted warning. Safe to call from multiple goroutines.

func (*WarningSink) Flush added in v1.95.0

func (s *WarningSink) Flush()

Flush writes every buffered warning to the sink's writer and clears the buffer. Safe to call multiple times.

func (*WarningSink) Len added in v1.95.0

func (s *WarningSink) Len() int

Len returns the number of buffered warnings.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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