Documentation ¶
Overview ¶
Package utils is collections of utility functions for the Whalelint project. It mostly involves slice versions of functions found in the strings package and some other helper ones.
Index ¶
- Variables
- func EqualsEither(str string, targetList []string) bool
- func FilterMapByKey(kv map[string]string, f func(string) bool) []string
- func FilterMapByValue(kv map[string]string, f func(string) bool) []string
- func FilterMapKeys(kv map[string]string, f func(string) bool) []string
- func FilterMapValues(kv map[string]string, f func(string) bool) []string
- func FindIndexOfSliceElement(arr []string, patternInterface interface{}) int
- func GetDockerfileAst(filePathString string) ([]instructions.Stage, []instructions.ArgCommand, error)
- func InsertIntoSlice(originalSlice []string, element string, index int) ([]string, error)
- func IsUnixPortValid(portParam interface{}) bool
- func MatchDockerImageNames(str1, str2 string) bool
- func ParseDockerfileInstructionsSafely(dockerfile *parser.Result, fileHandle io.ReadSeeker) ([]instructions.Stage, []instructions.ArgCommand)
- func ParseKeyValueMap(strList []string, separator rune, finishOnMiss bool) map[string]string
- func ReadFileContents(filePath string) (string, error)
- func RemoveExtraSpaces(str string, trim bool) string
- func SliceContains(arr []string, patternInterface interface{}) bool
- func SplitKeyValue(s string, r rune) (string, string)
- func SplitMulti(str string, patternSlice []string) []string
Constants ¶
This section is empty.
Variables ¶
var ErrOutOfBounds = errors.New("out of bounds")
ErrOutOfBounds is an error when indexing out of a slice.
var ErrUnSupportedType = errors.New("unsupported type")
Functions ¶
func EqualsEither ¶
EqualsEither returns true, if str string is a match to any element of the targetList, false otherwise.
func FindIndexOfSliceElement ¶
FindIndexOfSliceElement returns the fist index of the slice element that matched with the pattern. Pattern can be a string or a string slice. In the latter case the index of the match of the first element with any matching pattern will be returned.
func GetDockerfileAst ¶
func GetDockerfileAst(filePathString string) ([]instructions.Stage, []instructions.ArgCommand, error)
func InsertIntoSlice ¶
InsertIntoSlice inserts element at index into originalSlice.
func IsUnixPortValid ¶
func IsUnixPortValid(portParam interface{}) bool
func MatchDockerImageNames ¶
MatchDockerImageNames compares Docker image name strings with the addition of including the fact, that when no tag is specified, ":latest" is assumed.
func ParseDockerfileInstructionsSafely ¶
func ParseDockerfileInstructionsSafely(dockerfile *parser.Result, fileHandle io.ReadSeeker) ([]instructions.Stage, []instructions.ArgCommand)
ParseDockerfileInstructionsSafely parses Dockerfile Instructions representation by iteratively trying to correct the AST representation - if needed.
If there is an error, it tries to - find the offending line from the error message of buildkit::instructions::Parse - match that line to a dockerfile.AST.children element - remove that child - try again until there is
- either a valid AST tree that can be parsed further
- there is no more child, in which case it returns an empty stage.
nolint:funlen
func ParseKeyValueMap ¶
ParseKeyValueMap parses a string list into map[string]string based on the separator rune. If finishOnMiss is true, the parser terminates on the first element, where there is no separator rune present and returns with the map built so far without the last, unsplittable element.
func ReadFileContents ¶
func RemoveExtraSpaces ¶
RemoveExtraSpaces removes all extra consecutive spaces from a string.
func SliceContains ¶
func SplitKeyValue ¶
SplitKeyValue splits s string into two strings on the r rune. It's ideal for building maps, as there is always two element, a key and a value returned. Naturally, if there is no r rune present in s string, the second element will be an empty string.
func SplitMulti ¶
SplitMulti splits str string on any pattern match from patternSlice. Note: not-implemented!
Types ¶
This section is empty.