Documentation
¶
Index ¶
- Constants
- func DistinctSlice[T comparable](s []T) []T
- func EnvMap(environ []string) map[string]string
- func EqualsOrRegexMatchString(pattern string, s string, insensitive bool) bool
- func Error(a ...any)
- func Errorf(format string, a ...any)
- func GetenvOrDefault(key string, defaultValue string) string
- func Hdr(a ...any)
- func Hdrf(format string, a ...any)
- func MapContainsKey[K comparable, V interface{}](m map[K]V, key K) bool
- func MapIntKeysToSortedSlice[V interface{}](m map[int]V) []V
- func MarshalKoanfStructToBytes[T any](o T, p koanf.Parser) []byte
- func MarshalToJsonBytes[T any](o T) []byte
- func MarshalToYamlBytes[T any](o T) []byte
- func MergeMaps[K comparable, V interface{}](maps ...map[K]V) map[K]V
- func Msg(a ...any)
- func Msgf(format string, a ...any)
- func OsEnvMap() map[string]string
- func Print(a ...any)
- func PrintBanner()
- func PrintRowStatusTable(headers []string, rows [][]string, ...)
- func PrintTable(headers []string, rows [][]string)
- func Printf(format string, a ...any)
- func PromptYesNo(msg string) bool
- func RunOnce(key string, f func() error) error
- func SetWriter(w io.Writer)
- func ToInterfaceSlice[T any](s []T) []interface{}
- func ToTypedSlice[T any](s []interface{}) []T
- func TruncateString(s string, n int) string
- func TruncateStringE(s string, n int) string
- func ValueOrDefault[T comparable](val T, def T) T
- func WriteBytesToFile(b []byte, path string) error
- func WriteStringToFile(s string, path string) error
- func Zero[T any]() T
- type HttpClientFactory
- type HttpClientFactoryImpl
- type HttpClientFactoryMock
- type RoundTripFunc
- type RowStatus
Constants ¶
const ( StatusOk RowStatus = "[✔]" StatusWarning RowStatus = "[i]" StatusError RowStatus = "[✘]" StatusUnknown RowStatus = "" ColorOk = "#00AA00" ColorWarning = "#AAAA00" ColorError = "#AA0000" )
Constants for row statuses and their associated colors.
Variables ¶
This section is empty.
Functions ¶
func DistinctSlice ¶
func DistinctSlice[T comparable](s []T) []T
DistinctSlice returns a new slice with duplicate entries removed. The input slice must contain elements of a comparable type.
func EqualsOrRegexMatchString ¶
EqualsOrRegexMatchString checks if a string `s` matches a pattern strictly or via a regex. If `insensitive` is true, the match is case-insensitive.
func GetenvOrDefault ¶
GetenvOrDefault retrieves the value of the environment variable specified by `key`. If the variable is not set, it returns the provided `defaultValue`.
func MapContainsKey ¶
func MapContainsKey[K comparable, V interface{}](m map[K]V, key K) bool
MapContainsKey checks if a map contains a specific key.
func MapIntKeysToSortedSlice ¶
func MapIntKeysToSortedSlice[V interface{}](m map[int]V) []V
MapIntKeysToSortedSlice converts a map with integer keys into a slice of values, sorted by the integer keys in ascending order.
func MarshalKoanfStructToBytes ¶
MarshalKoanfStructToBytes marshals a struct of type `T` into bytes using the specified `koanf.Parser`. This function uses the Koanf library to handle the marshaling process.
func MarshalToJsonBytes ¶
MarshalToJsonBytes marshals a struct of type `T` into JSON-encoded bytes.
func MarshalToYamlBytes ¶
MarshalToYamlBytes marshals a struct of type `T` into YAML-encoded bytes.
func MergeMaps ¶
func MergeMaps[K comparable, V interface{}](maps ...map[K]V) map[K]V
MergeMaps performs a shallow merge of two or more maps into a single map. Duplicate keys in subsequent maps will take precedence and overwrite earlier values.
func PrintBanner ¶
func PrintBanner()
PrintBanner prints the Quartz ASCII art banner to the console.
func PrintRowStatusTable ¶
func PrintRowStatusTable(headers []string, rows [][]string, statusFunc func(i int, row []string) RowStatus)
PrintRowStatusTable prints a formatted table with a status indicator column to the console.
func PrintTable ¶
PrintTable prints a formatted table to the console.
func PromptYesNo ¶
PromptYesNo displays a yes/no prompt to the console and returns true if "yes" was selected.
func RunOnce ¶
RunOnce ensures that a function identified by the given key is only executed the first time. Subequent calls will return a cached response.
func ToInterfaceSlice ¶
func ToInterfaceSlice[T any](s []T) []interface{}
ToInterfaceSlice converts a typed slice to a slice of `interface{}`.
func ToTypedSlice ¶
func ToTypedSlice[T any](s []interface{}) []T
ToTypedSlice converts a slice of `interface{}` to a typed slice.
func TruncateString ¶
TruncateString truncates a string to the specified length `n`. If the string is shorter than or equal to `n`, it is returned unchanged.
func TruncateStringE ¶
TruncateStringE truncates a string to the specified length `n` and appends "..." if truncation occurs. If `n` is less than or equal to 3, the string is truncated without appending ellipses.
func ValueOrDefault ¶
func ValueOrDefault[T comparable](val T, def T) T
ValueOrDefault returns `val` if it is not the zero value of its type. Otherwise, it returns the provided default value `def`.
func WriteBytesToFile ¶
WriteBytesToFile writes bytes to a file at the given path. It creates any required directories as needed.
func WriteStringToFile ¶
WriteStringToFile writes a string to a file at the given path. It creates any required directories as needed.
Types ¶
type HttpClientFactory ¶
IHttpClientFactory defines an interface for creating new HTTP clients.
func NewHttpClientFactory ¶
func NewHttpClientFactory() HttpClientFactory
type HttpClientFactoryImpl ¶
type HttpClientFactoryImpl struct{}
HttpClientFactory is a default implementation of IHttpClientFactory that creates standard HTTP clients.
func (HttpClientFactoryImpl) NewClient ¶
func (f HttpClientFactoryImpl) NewClient() *http.Client
NewClient creates and returns a new instance of an HTTP client.
type HttpClientFactoryMock ¶
type HttpClientFactoryMock struct {
Callback RoundTripFunc
}
HttpClientFactoryMock is a mock implementation of IHttpClientFactory for testing purposes. It uses a custom RoundTripFunc to handle HTTP requests.
func (HttpClientFactoryMock) NewClient ¶
func (f HttpClientFactoryMock) NewClient() *http.Client
NewClient creates and returns a new instance of an HTTP client with a custom transport that uses the provided RoundTripFunc.
type RoundTripFunc ¶
RoundTripFunc defines a function type that processes HTTP requests and returns HTTP responses. It is used for mocking HTTP client behavior.