util

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 17 Imported by: 4

Documentation

Overview

Copyright 2023 Chainguard, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains added in v0.3.0

func Contains[T comparable](s []T, e T) bool

func Dedup added in v0.5.2

func Dedup[S ~[]E, E cmp.Ordered](s S) S

Dedup wraps slices.Sort and slices.Compact to deduplicate a slice.

func DownloadFile

func DownloadFile(ctx context.Context, uri string) (string, error)

DownloadFile downloads a file and returns a path to it in temporary storage.

func HashFile

func HashFile(downloadedFile string, digest hash.Hash) (string, error)

HashFile calculates the hash for a file and returns it as a hex string.

func MutateStringFromMap added in v0.5.0

func MutateStringFromMap(with map[string]string, input string) (string, error)

Given a string and a map, replace the variables in the string with values in the map

func NewTarFilter added in v0.4.0

func NewTarFilter(r io.ReadCloser, only string, trim bool) io.ReadCloser

NewTarFilter returns a new tar filter that will only return files that start with the value of only. Will strip leading '/' from only to match how tar files normally are constructed. If trim is true, the prefix will be trimmed from the returned files.

func ReverseSlice added in v0.3.0

func ReverseSlice[T comparable](s []T)

func RightJoinMap added in v0.5.0

func RightJoinMap(left map[string]string, right map[string]string) map[string]string

Given a left and right map, perform a right join and return the result

func SourceDateEpoch added in v0.5.2

func SourceDateEpoch(defaultTime time.Time) (time.Time, error)

SourceDateEpoch parses the SOURCE_DATE_EPOCH environment variable. If it is not set, it returns the defaultTime. If it is set, it MUST be an ASCII representation of an integer. If it is malformed, it returns an error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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