utils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BYTE = 1.0 << (10 * iota)
	KIBIBYTE
	MEBIBYTE
	GIBIBYTE
)

Variables

This section is empty.

Functions

func BytesString

func BytesString(bytes uint64, accuracy int) string

BytesString converts bytes into a human readable string. This function is inspired by https://www.reddit.com/r/golang/comments/8micn7/review_bytes_to_human_readable_format/

func CTFComponentArchiveFilename

func CTFComponentArchiveFilename(name, version string) string

CTFComponentArchiveFilename returns the name of the componant archive file in the ctf.

func CacheDir

func CacheDir() (string, error)

CacheDir returns the cache dir for the current cli command

func CalculateBlobUploadRef

func CalculateBlobUploadRef(repoCtx cdv2.OCIRegistryRepository, componentName string, componentVersion string) string

CalculateBlobUploadRef calculates the OCI reference where blobs for a component should be uploaded

func CleanMarkdownUsageFunc

func CleanMarkdownUsageFunc(cmd *cobra.Command)

CleanMarkdownUsageFunc removes markdown tags from the long usage of the command. With this func it is possible to generate the markdown docs but still have readable commandline help func. Note: currently only "<pre>" tags are removed

func ExponentialBackoff

func ExponentialBackoff(backoffFactor time.Duration, retries uint64) time.Duration

ExponentialBackoff calculates an exponential backoff timeout

func GetFileType

func GetFileType(fs vfs.FileSystem, path string) (string, error)

GetFileType returns the mimetype of a file.

func Gzip

func Gzip(data []byte, compressionLevel int) ([]byte, error)

Gzip applies gzip compression to an arbitrary byte slice

func PrintPrettyYaml

func PrintPrettyYaml(obj interface{}, enabled bool)

PrintPrettyYaml prints the given objects as yaml if enabled.

func RandomString

func RandomString(n int) string

RandomString creates a new random string with the given length.

func RawJSON

func RawJSON(value interface{}) (*json.RawMessage, error)

RawJSON converts an arbitrary value to json.RawMessage

func SafeConvert

func SafeConvert(bytes []byte) string

SafeConvert converts a byte slice to string. If the byte slice is nil, an empty string is returned.

func TargetOCIArtifactRef

func TargetOCIArtifactRef(targetRepo, ref string, keepOrigHost bool) (string, error)

TargetOCIArtifactRef calculates the target reference for

func WriteFileToTARArchive

func WriteFileToTARArchive(filename string, inputReader io.Reader, outputWriter *tar.Writer) error

WriteFileToTARArchive writes a new file with name=filename and content=inputReader to outputWriter

Types

This section is empty.

Jump to

Keyboard shortcuts

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