Documentation
¶
Overview ¶
Package util contains various utility functions for directories and files. It includes functions for formatting JSON, writing to files, directory management, and go control-flow helpers
Index ¶
- func BuildDirFileList(directory string) ([]string, error)
- func CalculateClusterIncludesExcludes(input map[string]string, filters PathFilterOptions) []string
- func CheckObjectMatch(input gjson.Result, filterString string) bool
- func CleanOutputDir(outputFileMap map[string]bool, componentOutputDir string) error
- func Colorize(input interface{}, colorNum int, disabled bool) string
- func ErrorIfCheck(message string, err error) error
- func FatalErrorCheck(message string, err error, logger zerolog.Logger)
- func FetchRepoUrl(url string, destination string, noop bool) error
- func Filter(vs []string, f func(string) bool) []string
- func FilterItems(input map[string]string, pFilter PathFilterOptions) []string
- func FormatJsonnetString(input string) (string, error)
- func FormatJsonnetStringCustom(input string, opts formatter.Options) (string, error)
- func GetClusterFilenames(searchDir string) ([]types.Kr8Cluster, error)
- func GetClusterParamsFilenames(basePath string, targetPath string) []string
- func GetClusterPath(searchDir string, clusterName string) (string, error)
- func GetDefaultFormatOptions() formatter.Options
- func HashFile(path string) (string, error)
- func JsonnetPrint(output string, format string, color bool) error
- func LogErrorIfCheck(message string, err error, logger zerolog.Logger) error
- func Pretty(inputJson string, colorOutput bool) (string, error)
- func ReadFile(file string) ([]byte, error)
- func ReadGzip(filename string) ([]byte, error)
- func SetupLogger(enableColor bool) zerolog.Logger
- func WriteFile(input []byte, file string) error
- func WriteGzip(input []byte, file string) error
- func WriteObjToJsonFile(filename string, path string, objStruct interface{}) (string, error)
- type PathFilterOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDirFileList ¶ added in v0.2.0
Walk a directory to build a list of all files in the tree.
func CalculateClusterIncludesExcludes ¶
func CalculateClusterIncludesExcludes(input map[string]string, filters PathFilterOptions) []string
Using the allClusterParams variable and command flags to create a list of clusters to generate. Clusters can be filtered with "=" for equality or "~" for regex match.
func CheckObjectMatch ¶
Checks if a input object matches a filter string. The filter string can be an equality match or a regex match.
func CleanOutputDir ¶
Given a map of filenames, prunes all *.yaml files that are NOT in the map from the directory.
func Colorize ¶
Colorize function from zerolog console.go file to replicate their coloring functionality. Source: https://github.com/rs/zerolog/blob/a21d6107dcda23e36bc5cfd00ce8fdbe8f3ddc23/console.go#L389 Replicated here because it's a private function.
func ErrorIfCheck ¶ added in v0.2.0
If err != nil, wraps it in a Kr8Error with the message.
func FatalErrorCheck ¶
Logs an error and exits the program if the error is not nil.
func FetchRepoUrl ¶
Fetch a git repo from a url and clone it to a destination directory. If the noop flag is true, it print commands to fetch manually without doing anything.
func Filter ¶
Filter returns a new slice containing only the elements that satisfy the predicate function. From https://gobyexample.com/collection-functions
func FilterItems ¶
func FilterItems(input map[string]string, pFilter PathFilterOptions) []string
Given a map of string, filter them based on the provided options. The map value is parsed as a gjson result and then checked against the provided options.
func FormatJsonnetString ¶
Formats a jsonnet string using the default options.
func FormatJsonnetStringCustom ¶
Formats a jsonnet string using custom options.
func GetClusterFilenames ¶
func GetClusterFilenames(searchDir string) ([]types.Kr8Cluster, error)
Get a list of cluster from within a directory. Walks the directory tree, creating a types.Kr8Cluster for each cluster.jsonnet file found.
func GetClusterParamsFilenames ¶
Get all cluster parameters within a directory. Walks through the directory hierarchy and returns all paths to `params.jsonnet` files.
func GetClusterPath ¶ added in v0.2.0
Get a specific cluster within a directory by name. [filepath.Walk]s the cluster directory tree searching for the given clusterName. Returns the path to the cluster.jsonnet file.
func GetDefaultFormatOptions ¶
Configures the default options for the jsonnet formatter.
func JsonnetPrint ¶
Print the jsonnet in the specified format. Acceptable formats are: yaml, stream, json.
func LogErrorIfCheck ¶ added in v0.2.0
If the error is not nil, log an error and wrap the error in a Kr8Error.
func Pretty ¶
Pretty formats the input jsonnet string with indentation and optional color output. Returns an error when the input can't properly format the json string input.
func SetupLogger ¶ added in v0.2.0
Configure zerolog with some defaults and cleanup error formatting.
Types ¶
type PathFilterOptions ¶
type PathFilterOptions struct {
// Comma-separated list of include filters
// Filters can include:
//
// regex filters using the "~" operator. For example, "name~^myRegex$"
// equality matches using the "=" operator. For example, "name=myValue"
// substring matches using the "=" operator. For example, "name=myValue"
//
// If no operator is provided, it is treated as a substring match against the "name" field.
Includes string
// Comma-separated list of exclude filters.
// Filters can include:
//
// regex filters using the "~" operator. For example, "name~^myRegex$"
// equality matches using the "=" operator. For example, "name=myValue"
// substring matches using the "=" operator. For example, "name=myValue"
//
// If no operator is provided, it is treated as a substring match against the "name" field.
Excludes string
// Comma separated cluster names.
// Filters keys on exact match.
Clusters string
// Comma separated component names.
Components string
}
Fill with string to include and exclude, using kr8's special parsing.