util

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UpdateListActionAdd     = "add"
	UpdateListActionRemove  = "remove"
	UpdateListActionReplace = "replace"
)
View Source
const EmptySet = "empty"

Name to clear map/list for CLI

Variables

View Source
var MaxK8sUdpPorts int = 1000

Functions

func AddMaps

func AddMaps(maps ...map[string]string) map[string]string

func AddStringSliceUniques

func AddStringSliceUniques(ss []string, add []string) []string

func CamelCase

func CamelCase(s string) string

func CapitalizeMessage

func CapitalizeMessage(msg string) string

func ContainerVersionParse

func ContainerVersionParse(version string) (*time.Time, error)

func ConvertPEMtoOpenSSH

func ConvertPEMtoOpenSSH(pemStr string) (string, error)

func CopyStringMap

func CopyStringMap(srcM map[string]string) map[string]string

Make a copy of a string map if the source map is nil, the result is an empty map

func DNSSanitize

func DNSSanitize(name string) string

DNSSanitize santizies the name string for RFC 1123 DNS format. Valid chars are only 0-9, a-z, and '-' and cannot start or end in '-'

func DockerSanitize

func DockerSanitize(name string) string

DockerSanitize sanitizes the name string (which is assumed to be a ValidName) to make it usable as a docker image name (no spaces and special chars other than - and . are allowed)

func EscapeJson

func EscapeJson(jsoninput string) string

func EscapeLDAPName

func EscapeLDAPName(name string) string

func GetEpochMillis

func GetEpochMillis(t time.Time) int64

Get the number of milliseconds since epoch for the time. This is used for ElasticSearch.

func GetExternalApiAddr

func GetExternalApiAddr(defaultApiAddr string) (string, error)

Get the external address with port when running under kubernetes. This allows horizontally scaled instances to talk to each other within a given k8s cluster.

func GetHeadersString

func GetHeadersString(header http.Header) string

func GetShardIndex

func GetShardIndex(key interface{}, numShards uint) uint64

Get the shard index based on the key and number of shards.

func GetWaitTime

func GetWaitTime(now time.Time, intervalSec, offsetSec float64) time.Duration

Get the time to wait based on the interval and offset. Intervals start at epoch time zero. Returns the time to wait until the next interval time. For example, if intervals are every 10 seconds, then triggers are at time 10,20,30,40,... If time is now 5, it is 5 seconds until trigger 10. If time is now 99, it is 1 second until trigger 100.

The intent is that the stats senders send stats more-or-less around the same time, and the aggregator processes those stats at the same interval, but some offset later, allowing the aggregator to receive stats from all senders for the current interval before processing. This assumes loose time synchronization between nodes in the system where the offset can compensate for differences in time synchronization.

func HeatSanitize

func HeatSanitize(name string) string

alphanumeric plus -_. first char must be alpha, <= 255 chars.

func HostnameSanitize

func HostnameSanitize(name string) string

HostnameSanitize makes a valid hostname, for which the rules are the same as DNSSanitize, but it cannot end in '-' and cannot be > 63 digits

func ImagePathParse

func ImagePathParse(imagepath string) (*url.URL, error)

func IsLatitudeValid

func IsLatitudeValid(latitude float64) bool

IsLatitudeValid checks that the latitude is within accepted ranges

func IsLongitudeValid

func IsLongitudeValid(longitude float64) bool

IsLongitudeValid checks that the longitude is within accepted ranges

func K8SLabelValueSanitize

func K8SLabelValueSanitize(label string) string

K8SLabelValueSanitize sanitizes a string to use as a metadata label value Label values must be 63 chars or less (can be empty), must begin and end with alphanumerics [a-z0-9A-Z], and may contain dashes, underscores, dots, and alphanumerics.

func K8SSanitize

func K8SSanitize(name string) string

func K8SServiceSanitize

func K8SServiceSanitize(name string) string

func MapsEqual

func MapsEqual(a, b map[string]string) bool

func NamespaceSanitize

func NamespaceSanitize(name string) string

Namespaces are limited to 63 characters and cannot end in "-"

func OpenUrl

func OpenUrl(url string) error

open opens the specified URL in the default browser of the user.

func QuoteArgs

func QuoteArgs(cmd string) (string, error)

func RandAscii

func RandAscii(n int) []byte

func RemoveExtension

func RemoveExtension(path string) string

RemoveExtension removes extension and all trailing dots after a filename. Nothing will be trimmed if no filename is detected. This behavior is different from strings.TrimSuffix(path, filepath.Ext(path)), which will trim any extension and trailing dot regardless of the filename, i.e. ".." will become ".".

func RemoveStringSliceUniques

func RemoveStringSliceUniques(ss []string, rm []string) []string

func ResolveExternalAddr

func ResolveExternalAddr() (string, error)

This is for figuring out the "external" address when running under kubernetes, which is really the internal CNI address that containers can use to talk to each other.

func SetExtension

func SetExtension(path, extension string) string

SetExtension adds an extension to path if the basename of path has a filename. It will replace any existing extension.

func SplitCamelCase

func SplitCamelCase(name string) []string

func StringSliceCopy

func StringSliceCopy(a []string) []string

func StringSliceEqual

func StringSliceEqual(a, b []string) bool

func TimeFromEpochMicros

func TimeFromEpochMicros(us int64) time.Time

func TrimScheme

func TrimScheme(addr string) string

func UnCamelCase

func UnCamelCase(name string) string

UnCamelCase converts camel case to lowercase separated by underscore

func UncapitalizeMessage

func UncapitalizeMessage(msg string) string

func UnescapeLDAPName

func UnescapeLDAPName(name string) string

func ValidCliArg

func ValidCliArg(arg string) bool

Valid CLI args must be all lowercase, and my only contain alphanumeric and period, and in the case of repeated objects, colons.

func ValidDNSName

func ValidDNSName(name string) error

func ValidDockerName

func ValidDockerName(name string) bool

func ValidEmail

func ValidEmail(email string) bool

func ValidIp

func ValidIp(ip []byte) bool

func ValidK8SContainerName

func ValidK8SContainerName(name string) error

func ValidKubernetesName

func ValidKubernetesName(name string) bool

func ValidLDAPName

func ValidLDAPName(name string) error

func ValidName

func ValidName(name string) bool

func ValidObjName

func ValidObjName(name string) error

func ValidRegion

func ValidRegion(name string) bool

func ValidStoragePath

func ValidStoragePath(path string) error

func ValidateImagePath

func ValidateImagePath(imagePath string) error

func ValidateImageVersion

func ValidateImageVersion(imgVersion string) error

func ValidateNames

func ValidateNames(names map[string]string) error

walk through the map of names and values and validate the values return an error about which key had invalid value

func ValidatePublicKey

func ValidatePublicKey(pemStr string) (*rsa.PublicKey, error)

Types

type EmptyStringJsonNumber

type EmptyStringJsonNumber json.Number

EmptyStringJsonNumber behaves like JsonNumber for valid numbers, but treats the empty string differently. JsonNumber marshals out the empty string as 0, but this marshals it out as the empty string. JsonNumber will fail to unmarshal the empty string, but this will allow it. This allows the field to distinguish between an unspecified value (the empty string) and a zero value.

func (EmptyStringJsonNumber) MarshalJSON

func (s EmptyStringJsonNumber) MarshalJSON() ([]byte, error)

func (*EmptyStringJsonNumber) UnmarshalJSON

func (s *EmptyStringJsonNumber) UnmarshalJSON(b []byte) error

type FormUrlEncodedClearer

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

func NewFormUrlEncodedClearer

func NewFormUrlEncodedClearer(fields ...string) *FormUrlEncodedClearer

func (*FormUrlEncodedClearer) Clear

func (s *FormUrlEncodedClearer) Clear(data []byte) []byte

type JSONRedactor

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

func NewJSONRedactor

func NewJSONRedactor(redactedVal string) *JSONRedactor

func (*JSONRedactor) AddKey

func (s *JSONRedactor) AddKey(key string) *JSONRedactor

func (*JSONRedactor) Redact

func (s *JSONRedactor) Redact(jsonData []byte) ([]byte, error)

type Mutex

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

func (*Mutex) InitCond

func (m *Mutex) InitCond(cond *sync.Cond)

func (*Mutex) Lock

func (m *Mutex) Lock()

func (*Mutex) Unlock

func (m *Mutex) Unlock()

type PortSpec

type PortSpec struct {
	Proto      string
	Port       string
	EndPort    string // mfw XXX ? why two type and parse rtns for AppPort? (3 actually kube.go is another)
	Tls        bool
	Nginx      bool
	MaxPktSize int64
}

func ParsePorts

func ParsePorts(accessPorts string) ([]PortSpec, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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