common

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package common provides general utility helper functions and types

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckHTTPClientConfigFiles added in v0.11.0

func CheckHTTPClientConfigFiles(config *config_util.HTTPClientConfig) ([]string, error)

CheckHTTPClientConfigFiles verifies the existence of any files provided in the config and returns all the paths provided in the config. These files paths will be passed to security manager to add ACL rules by the app if and when needed.

func ComputeExternalURL

func ComputeExternalURL(u, listenAddr string) (*url.URL, error)

ComputeExternalURL computes a sanitized external URL from a raw input. It infers unset URL parts from the OS and the given listen address.

func ConvertMapI2MapS

func ConvertMapI2MapS(v any) any

ConvertMapI2MapS walks the given dynamic object recursively, and converts maps with interface{} key type to maps with string key type. This function comes handy if you want to marshal a dynamic object into JSON where maps with interface{} key type are not allowed.

Recursion is implemented into values of the following types:

-map[interface{}]interface{}
-map[string]interface{}
-[]interface{}

When converting map[interface{}]interface{} to map[string]interface{}, fmt.Sprint() with default formatting is used to convert the key to a string key.

Nicked from https://github.com/icza/dyno

func GenerateKey

func GenerateKey(url string) uint64

GenerateKey generates a reproducible key from a given URL string.

func GetFreePort

func GetFreePort() (int, *net.TCPListener, error)

GetFreePort in this case makes the closing of the listener the responsibility of the caller to allow for a guarantee that multiple random port allocations don't collide.

func GetUUIDFromString

func GetUUIDFromString(stringSlice []string) (string, error)

GetUUIDFromString returns a UUID5 for given slice of strings.

func MakeConfig

func MakeConfig[T any](filePath string, expandEnvVars bool) (*T, error)

MakeConfig reads config file, merges with passed default config and returns updated config instance.

func NewGrafanaClient

func NewGrafanaClient(config *GrafanaWebConfig, logger *slog.Logger) (*grafana.Grafana, error)

NewGrafanaClient instantiates a new instance of Grafana client.

func NodelistParser

func NodelistParser(nodelistExp string) []string

NodelistParser expands SLURM NODELIST into slice of nodenames.

func Round

func Round(value int64, nearest int64, side string) int64

Round returns a closest value that is multiple of nearest based on side. If side is `left`, it returns value less or equal to nearest and if the side is `right`, it returns value more or equal to nearest. For every other value of `side`, it returns a value based on `math.Round()`.

func SanitizeFloat

func SanitizeFloat(v float64) float64

SanitizeFloat replaces +/-Inf and NaN with zero.

func TimeTrack

func TimeTrack(start time.Time, name string, logger *slog.Logger)

TimeTrack tracks execution time of each function.

Types

type GrafanaWebConfig

type GrafanaWebConfig struct {
	URL              string                       `yaml:"url"`
	TeamsIDs         []string                     `yaml:"teams_ids"`
	HTTPClientConfig config_util.HTTPClientConfig `yaml:",inline"`
}

GrafanaWebConfig makes HTTP Grafana config.

type Timespan

type Timespan time.Duration

Timespan is a custom type to format time.Duration.

func (Timespan) Format

func (t Timespan) Format(format string) string

Format formats the time.Duration.

Jump to

Keyboard shortcuts

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