utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

This package is taken from github.com/docker/docker/pkg/stringid It is used for generating and validating unique identifiers such as generating random strings, validating imageIds and validating truncated imageIDs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPathValid

func CheckPathValid(path string) (os.FileInfo, error)

Check if the path provided is a valid path, by calling stat on it if the path is invalid due to either non accesibility or existence an error is returned else FileInfo type is returned.

func CopyDirectory

func CopyDirectory(src, dst string) error

func CopyFile

func CopyFile(src, dst string) error

func CreateFileIfNotExist

func CreateFileIfNotExist(filePath string) error

func CreateIfNotExistDir

func CreateIfNotExistDir(dirPath string) error

Create the directory sequence in dirPath if it does not exist if there was an error while creating the directory it returns the error else it returns nil indicating success

func GenerateNonCryptoID

func GenerateNonCryptoID() string

GenerateNonCryptoID generates unique id without using cryptographically secure sources of random. It helps you to save entropy.

func GenerateRandomID

func GenerateRandomID() string

GenerateRandomID returns a unique id.

func GetAllDirectoriesName

func GetAllDirectoriesName(dirPath string) []string

This is very flexible and will not report any error even though it is not able to access the directory. It will return an empty list in such cases. The caller must take care of this.

func GetDirsInDir

func GetDirsInDir(dirPath string) (error, []string)

Returns a list of directory present in the provided directory

func GetDurationFromTimestamp

func GetDurationFromTimestamp(ts string) (time.Duration, error)

func GetUniqueStrings

func GetUniqueStrings(list []string) []string

From a list of strings generate a list containing only unique strings from the list.

func IsShortID

func IsShortID(id string) bool

IsShortID determines if an arbitrary string *looks like* a short ID.

func ParsePortMapping

func ParsePortMapping(portMap string) (uint32, uint32, error)

ParsePortMapping parses the port mapping string and return the required ports If the portMapping string is not valid, this returns an error. The format of the port mapping is `HOST_PORT:CONTAINER_PORT`

func RemoveDirRecursively

func RemoveDirRecursively(dirPath string) error

func RemoveFileIfExists

func RemoveFileIfExists(filePath string) error

func StringInSlice

func StringInSlice(a string, list []string) bool

Returns true if in slice

func Tar

func Tar(contextDir string, compression Compression, destinationDir string, additionalCtx map[string]string, subDirToSkip []string) error

Tar the provided context directory into the destination directory, additionalCtx is the context of one or more file which is to be added to the tar file

In this function the contextDir is the absolute path of the directory to be compressed to the tar archive. DestincationDir is the directory to put the obtained tar file into.

func TruncateID

func TruncateID(id string, maxLen int) string

TruncateID returns a shorthand version of a string identifier for convenience. A collision with other shorthands is very unlikely, but possible. In case of a collision a lookup with TruncIndex.Get() will fail, and the caller will need to use a longer prefix, or the full-length Id.

func TruncateString

func TruncateString(str string, maxLen int) string

func UInt32InList

func UInt32InList(a uint32, list []uint32) bool

func ValidateDirExists

func ValidateDirExists(dirPath string) error

Validates if the directory pointed by `dirPath` exists If the directory does not exist or is not accessible it will return an error. The path specified must also be a directory and not just a regular file.

func ValidateFileExists

func ValidateFileExists(filePath string) error

Validates if the file pointed by `filePath` exists. If the file does not exist or is not accessible it will return an error. The path specified must also be a valid file

func ValidateID

func ValidateID(id string) error

ValidateID checks whether an ID string is a valid image ID.

Types

type Compression

type Compression int
const (
	Gzip Compression = 1
)

Jump to

Keyboard shortcuts

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