utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CatchPanic

func CatchPanic(f func() error) (err error)

CatchPanic calls the given function and returns any panic as a standard error

func IsLowerCaseIdentifier

func IsLowerCaseIdentifier(id string) bool

IsLowerCaseIdentifier accepts only lowerCaseIdentifiers.

func IsUpperCaseIdentifier

func IsUpperCaseIdentifier(id string) bool

IsUpperCaseIdentifier accepts only UpperCaseIdentifiers.

func SourceCodeSHA256

func SourceCodeSHA256(directory string) (string, error)

SourceCodeSHA256 generates a SHA256 of the source code files in the indicated directory and its sub-directories. The directory is interpreted relative to the current working directory. Use "." to hash the current working directory.

func ToKebabCase

func ToKebabCase(id string) string

ToKebabCase converts a CamelCase identifier to kebab-case.

func ToSnakeCase

func ToSnakeCase(id string) string

ToSnakeCase converts a CamelCase identifier to snake_case.

func ValidateConfigName

func ValidateConfigName(name string) error

ValidateConfigName indicates if the name can be used for a config. Config names must start with a letter and contain only alphanumeric characters.

func ValidateHostname

func ValidateHostname(hostname string) error

ValidateHostname indicates if the hostname is a valid microservice hostname. Hostnames must contain only alphanumeric characters, hyphens, underscores and dot separators.

func ValidateTickerName

func ValidateTickerName(name string) error

ValidateTickerName indicates if the name can be used for a ticker. Ticker names must start with a letter and contain only alphanumeric characters.

Types

type SyncMap

type SyncMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

SyncMap is a map wrapped in a mutex.

func (*SyncMap[K, V]) Delete

func (sm *SyncMap[K, V]) Delete(key K)

Delete deletes the value for a key.

func (*SyncMap[K, V]) Load

func (sm *SyncMap[K, V]) Load(key K) (value V, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*SyncMap[K, V]) LoadOrStore

func (sm *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*SyncMap[K, V]) Store

func (sm *SyncMap[K, V]) Store(key K, value V)

Store sets the value for a key.

Jump to

Keyboard shortcuts

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