utils

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatHours = 1 << iota
	FormatMinutes
	FormatSeconds
	FormatMilliseconds
)
View Source
const (
	ConfigFilePermissions = 0600
)

Variables

View Source
var GlobalChannels []interface {
	Close()
	IsClosed() bool
	SetClosed()
	GetName() string
	GetChannel() interface{}
}
View Source
var GlobalChannelsMutex sync.Mutex

Functions

func AreAllChannelsClosed

func AreAllChannelsClosed() bool

func CaseInsensitiveContains

func CaseInsensitiveContains(s []string, t string) bool

func CloseAllChannels

func CloseAllChannels()

func CloseChannel

func CloseChannel(ch interface{})

CloseChannel closes a specific channel

func ConvertStringMapToStringPtrMap

func ConvertStringMapToStringPtrMap(m map[string]string) map[string]*string

func ConvertStringPtrMapToStringMap

func ConvertStringPtrMapToStringMap(m map[string]*string) map[string]string

func CreateAndRegisterChannel

func CreateAndRegisterChannel(channelType reflect.Type, name string, capacity int) interface{}

CreateAndRegisterChannel creates a new channel of the specified type and capacity, and registers it

func CreateShortID

func CreateShortID() string

CreateShortID generates a short ID of length 6

func DebugOpenChannels

func DebugOpenChannels()

func DeleteKeyFromConfig

func DeleteKeyFromConfig(key string) error

func Difference

func Difference(a, b []string) []string

Difference returns the elements in `a` that aren't in `b`.

func DumpGoroutines

func DumpGoroutines()

func EnsureAzureTags

func EnsureAzureTags(tags map[string]string, projectID, uniqueID string) map[string]string

func EnsureGCPLabels

func EnsureGCPLabels(labels map[string]string, projectID, uniqueID string) map[string]string

func ExpandPath

func ExpandPath(path string) (string, error)

func FormatDuration

func FormatDuration(d time.Duration, format int) string

func GenerateUniqueID

func GenerateUniqueID() string

GenerateUniqueID generates a unique ID of length 8

func GenerateUniqueName

func GenerateUniqueName(projectID, uniqueID string) string

func GetSafeDiskSize

func GetSafeDiskSize(i int) int32

func InitConfig

func InitConfig(configFile string) (string, error)

func InterfaceSliceToStringSlice

func InterfaceSliceToStringSlice(slice []interface{}) []string

interfaceSliceToStringSlice converts a slice of interfaces to a slice of strings

func IsChannelClosed

func IsChannelClosed(chName string) bool

func IsValidGUID

func IsValidGUID(guid string) bool

func ParseStringToIntOrZero

func ParseStringToIntOrZero(row string) int

func RegisterChannel

func RegisterChannel(ch interface{})

func RemoveDuplicates

func RemoveDuplicates(s []string) []string

func SafeConvertToInt32

func SafeConvertToInt32(value int) int32

func SafeDeref

func SafeDeref(s *string) string

safeDeref safely dereferences a string pointer. If the pointer is nil, it returns a placeholder.

func StringPtr

func StringPtr(s string) *string

func StripAndParseJSON

func StripAndParseJSON(input string) ([]map[string]interface{}, error)

func StructToMap

func StructToMap(obj interface{}) (map[string]interface{}, error)

func ToPtr

func ToPtr[T any](v T) *T

ToPtr returns a pointer to the given value

func TruncateString

func TruncateString(s string, maxLength int) string

Types

type CircularBuffer

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

func NewCircularBuffer

func NewCircularBuffer[T any](size int) *CircularBuffer[T]

func (*CircularBuffer[T]) Add

func (cb *CircularBuffer[T]) Add(line T)

func (*CircularBuffer[T]) GetLines

func (cb *CircularBuffer[T]) GetLines() []T

type Config

type Config struct {
	AWS struct {
		Regions []string `yaml:"regions"`
	} `yaml:"aws"`
	GCP struct {
		ProjectID string `yaml:"project_id"`
	} `yaml:"gcp"`
}

type SafeChannel

type SafeChannel struct {
	Ch     interface{}
	Closed bool
	Mu     sync.Mutex
	Name   string
}

func NewSafeChannel

func NewSafeChannel(ch interface{}, name string) *SafeChannel

func (*SafeChannel) Close

func (sc *SafeChannel) Close()

func (*SafeChannel) GetChannel

func (sc *SafeChannel) GetChannel() interface{}

func (*SafeChannel) GetName

func (sc *SafeChannel) GetName() string

func (*SafeChannel) IsClosed

func (sc *SafeChannel) IsClosed() bool

func (*SafeChannel) SetClosed

func (sc *SafeChannel) SetClosed()

Jump to

Keyboard shortcuts

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