util

package
v7.0.1-0...-b8e8e6a Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: Apache-2.0 Imports: 19 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultLicensePrefixFilters for LoadLicenseFiles, NOTICE and LICENSE
	DefaultLicensePrefixFilters = []string{"LICENSE", "NOTICE"}
)

Functions

func ConvertNameToKey

func ConvertNameToKey(name string) string

ConvertNameToKey transforms a parameter name into a key acceptable to kube.

func CopyFileToTarStream

func CopyFileToTarStream(stream *tar.Writer, path string, header *tar.Header) error

CopyFileToTarStream writes a file to a tar stream

func DownloadFile

func DownloadFile(filepath string, url string, progressEvent progressDelegate) error

DownloadFile will download a url to a local file. It's efficient because it will write as it downloads and not load the whole file into memory.

func Hash

func Hash(name string) string

Hash returns a printable hash of the name

func JSONMarshal

func JSONMarshal(input interface{}) ([]byte, error)

JSONMarshal marshals an arbitrary map to JSON; this only exists because JSON.Marshal insists on having maps that have string (and not interface{}) keys

func LoadLicenseFiles

func LoadLicenseFiles(filename string, targz io.Reader, prefixFilters ...string) (map[string][]byte, error)

LoadLicenseFiles iterates through a tar.gz file looking for anything that matches prefixFilters. Filename is for error generation only.

func NewMarshalAdapter

func NewMarshalAdapter(m Marshaler) interface{}

NewMarshalAdapter creates a new adapter for JSON/YAML marshalling

func PrefixString

func PrefixString(str, prefix, separator string) string

PrefixString prefixes the provided 'str' with 'prefix' using 'separator' between them.

func QuoteList

func QuoteList(words []string) []string

QuoteList returns an array of quoted strings.

func SanitizeDockerName

func SanitizeDockerName(name string) string

SanitizeDockerName makes a string conform with the rules for Docker names

func StringInSlice

func StringInSlice(needle string, haystack []string) bool

StringInSlice checks if the given string is in the given string slice, ignoring case differences.

func TargzIterate

func TargzIterate(filename string, targz io.Reader, fn func(*tar.Reader, *tar.Header) error) error

TargzIterate iterates over the files it finds in a tar.gz file and calls a callback for each file encountered. Filename is only used for error generation.

func TempDir

func TempDir(dir, prefix string) (name string, err error)

TempDir overrides the default TempDir, since Docker needs this to be in your user folder.

func ValidatePath

func ValidatePath(path string, shouldBeDir bool, pathDescription string) error

ValidatePath validates that a path (file or dir) exists

func WordList

func WordList(words []string, conjunction string) string

WordList returns a string of all words in the 'words' slice. For 2 or more words the last word is prefixed by `conjunction`, and if there are at least 3 words, then they are separated by the oxford comma.

WordList([]string{"foo", "bar"}, "and") => "foo and bar" WordList([]string{"foo", "bar", "baz"}, "or") => "foo, bar, or baz"

func WriteToTarStream

func WriteToTarStream(stream *tar.Writer, data []byte, header tar.Header) error

WriteToTarStream writes a byte array of data into a tar stream

Types

type Marshaler

type Marshaler interface {
	Marshal() (interface{}, error)
}

The Marshaler interface is implemented by types which require custom marshalling support for dumping as JSON / YAML

type ModelGrapher

type ModelGrapher interface {
	// GraphNode inserts a new node into the graph
	GraphNode(nodeName string, attrs map[string]string) error
	// GraphEdge inserts a new edge into the graph
	GraphEdge(fromNode, toNode string, attrs map[string]string) error
}

ModelGrapher is an interface to emit dependency graphs of the various elements for troubleshooting purposes. It must accept emitting the same node / edge multiple times.

type SyncedWriter

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

SyncedWriter is a io.Writer with a mutex to guard writing from multiple threads

func NewSyncedWriter

func NewSyncedWriter(writer io.Writer) *SyncedWriter

NewSyncedWriter returns a SyncedWriter which wraps the given io.Writer

func (*SyncedWriter) Write

func (w *SyncedWriter) Write(p []byte) (n int, err error)

Write implements io.Writer for SyncedWriter

Jump to

Keyboard shortcuts

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