truncate

package
v0.10.0-rc Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package truncate provides functions for truncating Kubernetes values in a predictable way offering mildly collision safe values usable in deterministic field searches.

Index

Constants

View Source
const (
	// LabelNameLength is the max length of a name fragment in a label
	LabelNameLength = 63

	// LabelValueLength is the max length of a label value
	LabelValueLength = 63

	// ResourceNameLength is the max length of a resource name or a label with
	// optional prefix and name
	ResourceNameLength = 253

	// DefaultSuffixLength is the length of combined separator and checksum
	// characters that will be used as a truncation suffix in Label and Resource
	// truncation functions
	DefaultSuffixLength = 6
)

Variables

This section is empty.

Functions

func LabelName

func LabelName(str string) string

LabelName predictably truncates the supplied string using label name length restrictions and a uniform distribution suffix based on the string

func LabelValue

func LabelValue(str string) string

LabelValue predictably truncates the supplied string using label value length restrictions and a uniform distribution suffix based on the string

func ResourceName

func ResourceName(str string) string

ResourceName predictably truncates the supplied string using resource name length restrictions and a uniform distribution suffix based on the string

func Truncate

func Truncate(str string, length, suffixLength int) (string, error)

Truncate replaces the suffixLength number of trailing characters from str with a consistent hash fragment based on that string. The suffix will include a leading hyphen.

An error will be returned if the truncation length is less than the suffixLength, or truncation length is greater than sha1Length, or the suffix length is less than 2.

Example: If the base32 sum of a digest of "aaaaaaaaaaa" is "ovo", with a suffix length of 4:

Truncating this string to a length of 11 would result in "aaaaaaaaaaa" Truncating this string to a length of 8 would result in "aaaa-ovo" Truncating this string to a length of 7 would result in "aaa-ovo" Truncating this string to a length of 5 would result in "a-ovo" Truncating this string to a length of 4 would result in "-ovo"

Types

This section is empty.

Jump to

Keyboard shortcuts

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