utils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrOutOfBounds = errors.New("out of bounds")

ErrOutOfBounds is an error when indexing out of a slice.

View Source
var ErrUnSupportedType = errors.New("unsupported type")

Functions

func EqualsEither

func EqualsEither(str string, targetList []string) bool

EqualsEither returns true, if str string is a match to any element of the targetList, false otherwise.

func FilterMapByKey

func FilterMapByKey(kv map[string]string, f func(string) bool) []string

func FilterMapByValue

func FilterMapByValue(kv map[string]string, f func(string) bool) []string

func FilterMapKeys

func FilterMapKeys(kv map[string]string, f func(string) bool) []string

func FilterMapValues

func FilterMapValues(kv map[string]string, f func(string) bool) []string

func FindIndexOfSliceElement

func FindIndexOfSliceElement(arr []string, patternInterface interface{}) int

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

func InsertIntoSlice(originalSlice []string, element string, index int) ([]string, error)

InsertIntoSlice inserts element at index into originalSlice.

func IsUnixPortValid

func IsUnixPortValid(portParam interface{}) bool

func MatchDockerImageNames

func MatchDockerImageNames(str1, str2 string) bool

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

func ParseKeyValueMap(strList []string, separator rune, finishOnMiss bool) map[string]string

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 ReadFileContents(filePath string) (string, error)

func RemoveExtraSpaces

func RemoveExtraSpaces(str string, trim bool) string

RemoveExtraSpaces removes all extra consecutive spaces from a string.

func SliceContains

func SliceContains(arr []string, patternInterface interface{}) bool

func SplitKeyValue

func SplitKeyValue(s string, r rune) (string, string)

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

func SplitMulti(str string, patternSlice []string) []string

SplitMulti splits str string on any pattern match from patternSlice. Note: not-implemented!

Types

This section is empty.

Jump to

Keyboard shortcuts

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