utils

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Common symbols
	SymCheckMark = "✔"
	SymCrossMark = "✘"
	SymInfinity  = "∞"
	SymBullet    = "•"
)

Variables

View Source
var (
	BlackStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{
		Light: "0",
		Dark:  "8",
	})
	RedStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{
		Light: "1",
		Dark:  "9",
	})
	GreenStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{
		Light: "2",
		Dark:  "10",
	})
	YellowStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{
		Light: "3",
		Dark:  "11",
	})
	BlueStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{
		Light: "4",
		Dark:  "12",
	})
	MagentaStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{
		Light: "5",
		Dark:  "13",
	})
	CyanStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{
		Light: "6",
		Dark:  "14",
	})
	WhiteStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{
		Light: "7",
		Dark:  "15",
	})

	TableHeaderStyle = lipgloss.NewStyle().Bold(true).Padding(0, 1)
	TableRowStyle    = lipgloss.NewStyle().Padding(0, 1)
)
View Source
var (
	ErrorPrefix   = RedStyle.Bold(true).Render("Error: ")
	WarningPrefix = YellowStyle.Bold(true).Render("Warning: ")
)
View Source
var (
	TestFunctionResultStyle = TestFunctionResult{
		EmptyText:  "<empty>",
		EmptyStyle: BlackStyle,
		ErrorStyle: RedStyle,
		ValueStyle: GreenStyle,
	}

	TestFunctionResultListStyle = TestFunctionResult{
		EmptyText:  "<empty>",
		EmptyStyle: BlackStyle,
		ErrorStyle: RedStyle,
		ValueStyle: GreenStyle,
	}

	MaybeEnabledStyle = MaybeEnabled{
		TrueText:             SymCheckMark,
		TrueStyle:            GreenStyle.Bold(true),
		FalseText:            SymCrossMark,
		FalseStyle:           RedStyle.Bold(true),
		InheritedFalsePrefix: "",
		InheritedFalseSuffix: "*",
		InheritedFalseStyle:  RedStyle.Bold(true),
		NullText:             "-",
		NullStyle:            BlackStyle,
	}

	MaybeEnabledTableStyle = MaybeEnabled{
		TrueText:             SymCheckMark,
		TrueStyle:            GreenStyle.Bold(true),
		FalseText:            SymCrossMark,
		FalseStyle:           RedStyle.Bold(true),
		InheritedFalsePrefix: " ",
		InheritedFalseSuffix: "*",
		InheritedFalseStyle:  RedStyle.Bold(true),
		NullText:             "-",
		NullStyle:            BlackStyle,
	}

	MaybeEmptyStyle = MaybeEmpty{
		EmptyText:  "<empty>",
		EmptyStyle: BlackStyle,
		NullText:   "-",
		NullStyle:  BlackStyle,
	}

	MaybeWildcardNameStyle = MaybeEmpty{
		NullText:  "%",
		NullStyle: CyanStyle.Bold(true),
	}

	MaybeZeroStyle = MaybeZero{
		ZeroText:  "0",
		ZeroStyle: YellowStyle.Bold(true),
	}

	MaybeTimeStyle = MaybeTime{
		NullText:  "-",
		NullStyle: BlackStyle,
		Format:    "2006-01-02 15:04:05",
	}

	MaybeIDSuffixStyle = MaybeIDSuffix{
		SuffixStyle: BlueStyle,
		NullText:    "-",
		NullStyle:   BlackStyle,
	}

	MaybePasswordStyle = MaybePassword{
		NullText:    "-",
		NullStyle:   BlackStyle,
		HiddenText:  "***",
		HiddenStyle: BlueStyle.Bold(true),
	}

	MaybeQuotaStyle = MaybeQuota{
		UnlimitedText:  SymInfinity,
		UnlimitedStyle: MagentaStyle.Bold(true),
	}

	SQLLikeStyle = SQLLike{
		WildcardStyle: CyanStyle.Bold(true),
	}
)

Functions

func FormatBytes

func FormatBytes(b uint64) string

FormatBytes converts a size in bytes (uint64) to a human-readable string using 1024-based units. Examples:

0 -> "0 B"
512 -> "512 B"
1536 -> "1.5 KB"
1048576 -> "1 MB"

func ParseDomainFQDN

func ParseDomainFQDN(fqdn string) (string, error)

ParseDomainFQDN validates a domain using the same rules as the SQL schema.

func PasswordHash

func PasswordHash(password, method string) (string, error)

func PrintError

func PrintError(err error)

func PrintErrorWithMessage

func PrintErrorWithMessage(message string, err error)

func PrintSuccess

func PrintSuccess(message string)

func PrintWarning

func PrintWarning(message string)

func ToBoolPtr

func ToBoolPtr(value any) (*bool, bool)

ToBoolPtr converts various types to a *bool. Supported are: bool, *bool, sql.NullBool.

func ToStringPtr

func ToStringPtr(value any) (*string, bool)

ToStringPtr converts various types to a *string. Supported are: string, *string, sql.NullString.

func ToTimePtr

func ToTimePtr(value any) (*time.Time, bool)

ToTimePtr converts various types to a *time.Time. Supported are: time.Time, *time.Time, sql.NullTime.

func ToUint64Ptr

func ToUint64Ptr(value any) (*uint64, bool)

ToUint64Ptr converts various types to a *uint64. Supported are: - uint64, *uint64, int64, *int64, sql.NullInt64 - uint32, *uint32, int32, *int32, sql.NullInt32 - uint16, *uint16, int16, *int16, sql.NullInt16 - uint8, *uint8, int8, *int8 - uint, *uint, int, *int

func TransportString

func TransportString(method, host string, port *uint16, mxLookup bool) string

Types

type EmailAddress

type EmailAddress struct {
	LocalPart  string
	DomainFQDN string
}

func ParseEmailAddress

func ParseEmailAddress(address string) (EmailAddress, error)

func (*EmailAddress) String

func (ea *EmailAddress) String() string

type EmailAddressOrWildcard

type EmailAddressOrWildcard struct {
	LocalPart  *string
	DomainFQDN string
}

func ParseEmailAddressOrWildcard

func ParseEmailAddressOrWildcard(address string) (EmailAddressOrWildcard, error)

func (*EmailAddressOrWildcard) IsWildcard

func (ea *EmailAddressOrWildcard) IsWildcard() bool

func (*EmailAddressOrWildcard) String

func (ea *EmailAddressOrWildcard) String() string

type MaybeEmpty

type MaybeEmpty struct {
	EmptyText  string
	EmptyStyle lipgloss.Style
	NullText   string
	NullStyle  lipgloss.Style
}

func (MaybeEmpty) Render

func (me MaybeEmpty) Render(value any) string

type MaybeEnabled

type MaybeEnabled struct {
	TrueText             string
	TrueStyle            lipgloss.Style
	FalseText            string
	FalseStyle           lipgloss.Style
	InheritedFalsePrefix string
	InheritedFalseSuffix string
	InheritedFalseStyle  lipgloss.Style
	NullText             string
	NullStyle            lipgloss.Style
}

func (MaybeEnabled) Render

func (e MaybeEnabled) Render(value any, inherited ...any) string

type MaybeIDSuffix

type MaybeIDSuffix struct {
	SuffixStyle lipgloss.Style
	NullText    string
	NullStyle   lipgloss.Style
}

func (MaybeIDSuffix) Render

func (ids MaybeIDSuffix) Render(str any, suffix any) string

type MaybePassword

type MaybePassword struct {
	NullText    string
	NullStyle   lipgloss.Style
	HiddenText  string
	HiddenStyle lipgloss.Style
}

func (MaybePassword) Render

func (mp MaybePassword) Render(isSet any) string

type MaybeQuota

type MaybeQuota struct {
	UnlimitedText  string
	UnlimitedStyle lipgloss.Style
}

func (MaybeQuota) Render

func (mq MaybeQuota) Render(quotaBytes any, scaling uint64) string

type MaybeTime

type MaybeTime struct {
	NullText  string
	NullStyle lipgloss.Style
	Format    string
}

func (MaybeTime) Render

func (mt MaybeTime) Render(value any) string

type MaybeZero

type MaybeZero struct {
	ZeroText  string
	ZeroStyle lipgloss.Style
}

func (MaybeZero) Render

func (mz MaybeZero) Render(value any) string

type SQLLike

type SQLLike struct {
	WildcardStyle lipgloss.Style
}

func (SQLLike) Render

func (sl SQLLike) Render(str string) string

type TestFunctionResult

type TestFunctionResult struct {
	EmptyText  string
	EmptyStyle lipgloss.Style
	ErrorStyle lipgloss.Style
	ValueStyle lipgloss.Style
}

func (TestFunctionResult) Render

func (fr TestFunctionResult) Render(result any, err error) string

Directories

Path Synopsis
crypto

Jump to

Keyboard shortcuts

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