utils

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package utils contains utility functions

Package utils contains utility functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendFile added in v0.90.0

func AppendFile(filePath string, data []byte) error

AppendFile appends data to the filePath. It creates the file if it doesn’t already exist.

func ContainsRegistry added in v1.3.0

func ContainsRegistry(registries []string, registryHost string) bool

ContainsRegistry returns true if the specified registryHost is part of registries

func ContainsString

func ContainsString(arr []string, str string) bool

ContainsString checks the string contains in string array

func CopyFile added in v0.0.4

func CopyFile(sourceFile, destFile string) error

CopyFile copies source file to dest file

func EnsureMutualExclusiveCurrentContexts added in v1.1.0

func EnsureMutualExclusiveCurrentContexts() error

EnsureMutualExclusiveCurrentContexts ensures mutual exclusive behavior among k8s and tanzu current contexts, i.e, if both k8s and tanzu current contexts types are set (a case where plugin using old plugin-runtime API can set k8s current context though tanzu current context is set by CLI or plugin with latest plugin-runtime in config file) it would remove the tanzu current context to maintain backward compatibility

func GenerateKey added in v1.0.0

func GenerateKey(parts ...string) string

GenerateKey is a utility function that takes an arbitrary number of string arguments, concatenates them with a colon (":") separator, and returns the resulting string. This function is typically used to create a unique key or identifier from multiple string parts.

Parameters: parts: A variadic parameter that accepts an arbitrary number of strings.

Returns: A single string that is the result of concatenating all input strings with a colon (":") separator.

func IsFileEmpty added in v0.90.0

func IsFileEmpty(filename string) (bool, error)

IsFileEmpty returns true if file/directory is empty otherwise returns false

func IsNewVersion added in v1.0.0

func IsNewVersion(incomingVersionStr, existingVersionStr string) bool

IsNewVersion compares the plugin version and the installed version.

func IsPreRelease added in v1.3.0

func IsPreRelease(versionStr string) bool

IsPreRelease checks if the version is a pre-release version.

func IsSameMajor added in v1.3.0

func IsSameMajor(v1str, v2str string) bool

IsSameMajor compares two versions and returns true if they are the same major version.

func IsSameMinor added in v1.3.0

func IsSameMinor(v1str, v2str string) bool

IsSameMinor compares two versions and returns true if they are the same minor version.

func JoinURL added in v0.90.0

func JoinURL(baseURL, relativeURL string) (string, error)

JoinURL joins a base URL and a relative URL intelligently, ensuring that there are no unnecessary or duplicate slashes. It handles URLs where the base URL ends with a slash and the relative URL begins with a slash.

Parameters: baseURL: The base URL as a string. relativeURL: The relative URL as a string. It could start with a slash, but it's not necessary.

Returns: A string that is the concatenation of baseURL and relativeURL, formatted correctly. An error if there was a problem parsing the base URL.

func PanicOnErr added in v1.1.0

func PanicOnErr(err error)

PanicOnErr calls 'panic' if 'err' is non-nil.

func ParsePluginID added in v1.3.0

func ParsePluginID(pluginID string) (string, string, string)

ParsePluginID parses the plugin id and returns (name, target, version) strings

func PathExists

func PathExists(dir string) bool

PathExists returns true if file/directory exists otherwise returns false

func SaveFile

func SaveFile(filePath string, data []byte) error

SaveFile saves the file to the provided path Also creates missing directories if any

func SortVersions

func SortVersions(vStrArr []string) error

SortVersions sorts the supported version strings in ascending semver 2.0 order.

Types

This section is empty.

Jump to

Keyboard shortcuts

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