utils

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SSLModeRequire    = "require"
	SSLModeDisable    = "disable"
	SSLModeVerifyCA   = "verify-ca"
	SSLModeVerifyFull = "verify-full"

	Unknown = ""
)

Variables

This section is empty.

Functions

func Absolute

func Absolute[T int | int8 | int16 | int32 | int64 | float32 | float64](value T) T

func AddConstantToInterface

func AddConstantToInterface(val interface{}, increment int) (interface{}, error)

func ArrayContains

func ArrayContains[T any](set []T, match func(elem T) bool) (int, bool)

func CheckIfFilesExists

func CheckIfFilesExists(files ...string) error

func CompareInterfaceValue

func CompareInterfaceValue(a, b interface{}) int

return 0 for equal, -1 if a < b else 1 if a>b

func ComputeConfigHash added in v0.1.2

func ComputeConfigHash(srcPath, destPath string) string

func Concurrent

func Concurrent[T any](ctx context.Context, array []T, concurrency int, execute func(ctx context.Context, one T, executionNumber int) error) error

func ConcurrentC

func ConcurrentC[T any](ctx context.Context, next *Next[T], concurrency int, execute func(ctx context.Context, one T, sequence int64) error) error

func ConcurrentF

func ConcurrentF(ctx context.Context, functions ...CtxFunc) error

func ConcurrentInGroup

func ConcurrentInGroup[T any](group *CxGroup, array []T, execute func(ctx context.Context, one T) error)

func ConvertToString

func ConvertToString(value interface{}) string

func DetermineSystemMemoryGB

func DetermineSystemMemoryGB() int64

DetermineSystemMemoryGB returns the total system memory in GB. Returns -1 if unable to determine memory.

func ErrExec

func ErrExec(functions ...func() error) error

func ErrExecFormat

func ErrExecFormat(format string, function func() error) func() error

func ErrExecSequential

func ErrExecSequential(functions ...func() error) error

func ExistInArray

func ExistInArray[T ~string | int | int8 | int16 | int32 | int64 | float32 | float64](set []T, value T) bool

func ForEach

func ForEach[T any](set []T, action func(elem T) error) error

func GetHash

func GetHash(m map[string]interface{}) string

GetHash returns GetKeysHash result with keys from m

func GetKeysHash

func GetKeysHash(m map[string]interface{}, keys ...string) string

GetKeysHash returns md5 hashsum of concatenated map values (sort keys before)

func IsInstance

func IsInstance(val any, typ reflect.Kind) bool

func IsJSON

func IsJSON(str string) bool

func IsOfType

func IsOfType(object any, decidingKey string) (bool, error)

func IsSubset

func IsSubset[T comparable](setArray, subsetArray []T) bool

func IsValidSubcommand

func IsValidSubcommand(available []*cobra.Command, sub string) bool

IsValidSubcommand checks if the passed subcommand is supported by the parent command

func MaxDate

func MaxDate(v1, v2 time.Time) time.Time

func SizeOf

func SizeOf(v any) int

Of returns the size of 'v' in bytes. If there is an error during calculation, Of returns -1.

func StreamIdentifier

func StreamIdentifier(name, namespace string) string

func Ternary

func Ternary(cond bool, a, b any) any

returns cond ? a ; b (note: it is not function ternary)

func TimestampedFileName

func TimestampedFileName(extension string) string

Returns a timestamped

func ULID

func ULID() string

func Unmarshal

func Unmarshal(from, object any) error

Unmarshal serializes and deserializes any from into the object return error if occurred

func UnmarshalFile

func UnmarshalFile(file string, dest any) error

func Validate

func Validate[T any](structure T) error

Types

type CtxFunc

type CtxFunc = func(ctx context.Context) error

type CxGroup

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

func NewCGroup

func NewCGroup(ctx context.Context) *CxGroup

func NewCGroupWithLimit

func NewCGroupWithLimit(ctx context.Context, limit int) *CxGroup

func (*CxGroup) Add

func (g *CxGroup) Add(execute func(ctx context.Context) error)

func (*CxGroup) Block

func (g *CxGroup) Block() error

func (*CxGroup) Ctx

func (g *CxGroup) Ctx() context.Context

type Next

type Next[T any] struct {
	// contains filtered or unexported fields
}

func Yield

func Yield[T any](next func(prev T) (bool, T, error)) *Next[T]

func (*Next[T]) Close

func (n *Next[T]) Close()

func (*Next[T]) Next

func (n *Next[T]) Next() bool

type SSLConfig

type SSLConfig struct {
	// SSL mode
	//
	// @jsonschema(
	// required=true,
	// enum=["require","disable","verify-ca","verify-full"]
	// )
	Mode string `mapstructure:"mode,omitempty" json:"mode,omitempty" yaml:"mode,omitempty"`
	// CA Certificate
	//
	// @jsonschema(
	// title="CA Certificate"
	// )
	ServerCA string `mapstructure:"server_ca,omitempty" json:"server_ca,omitempty" yaml:"server_ca,omitempty"`
	// Client Certificate
	//
	// @jsonschema(
	// title="Client Certificate"
	// )
	ClientCert string `mapstructure:"client_cert,omitempty" json:"client_cert,omitempty" yaml:"client_cert,omitempty"`
	// Client Certificate Key
	//
	// @jsonschema(
	// title="Client Certificate Key"
	// )
	ClientKey string `mapstructure:"client_key,omitempty" json:"client_key,omitempty" yaml:"client_key,omitempty"`
}

SSLConfig is a dto for deserialized SSL configuration for Postgres

func (*SSLConfig) Validate

func (sc *SSLConfig) Validate() error

Validate returns err if the ssl configuration is invalid

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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