Documentation
¶
Overview ¶
Package utils contains utility functions
Package utils contains utility functions
Index ¶
- func AppendFile(filePath string, data []byte) error
- func ContainsString(arr []string, str string) bool
- func CopyFile(sourceFile, destFile string) error
- func EnsureMutualExclusiveCurrentContexts() error
- func GenerateKey(parts ...string) string
- func IsFileEmpty(filename string) (bool, error)
- func IsNewVersion(incomingVersionStr, existingVersionStr string) bool
- func JoinURL(baseURL, relativeURL string) (string, error)
- func PanicOnErr(err error)
- func PathExists(dir string) bool
- func SaveFile(filePath string, data []byte) error
- func SortVersions(vStrArr []string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendFile ¶ added in v0.90.0
AppendFile appends data to the filePath. It creates the file if it doesn’t already exist.
func ContainsString ¶
ContainsString checks the string contains in string array
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
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
IsFileEmpty returns true if file/directory is empty otherwise returns false
func IsNewVersion ¶ added in v1.0.0
IsNewVersion compares the plugin version and the installed version.
func JoinURL ¶ added in v0.90.0
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 PathExists ¶
PathExists returns true if file/directory exists otherwise returns false
func SaveFile ¶
SaveFile saves the file to the provided path Also creates missing directories if any
func SortVersions ¶
SortVersions sorts the supported version strings in ascending semver 2.0 order.
Types ¶
This section is empty.