utils

package
v0.0.0-...-0d25880 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CompressorNone - uncompressed file
	CompressorNone = iota

	// CompressorGzip indicates that the file i compressed using gzip
	CompressorGzip

	// CompressorBzip2 indicates a bzip2 compressor
	CompressorBzip2

	// CompressorZip indicates a zlib compressor
	CompressorZip

	// CompressorXZ indicates a xz compressor
	CompressorXZ
)

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(src, dst string)

CopyDir copies directory at src to dst, recursively

func CopyFile

func CopyFile(src, dst string, mode os.FileMode)

CopyFile copies a file from src to dst and setting the mode of dst

func CreateDir

func CreateDir(targetDir, dirPath string, mode os.FileMode)

CreateDir creates a directory at the given path.

func CreateFile

func CreateFile(src io.Reader, targetdir, filename string, mode os.FileMode)

CreateFile creates a file from an io.Reader with a given mode

func CreateFile2

func CreateFile2(file *zip.File, targetdir, filename string, mode os.FileMode)

CreateFile2 creates a file from an io.Reader with a given mode

func DeepCopy

func DeepCopy(src interface{}) interface{}

DeepCopy copies all public properties of src into the return value, that is a value of the same type as src.

func DownloadFile

func DownloadFile(file, url string)

DownloadFile downloads a file to a specific location

func DownloadGit

func DownloadGit(src, dst string)

DownloadGit downloads a url in the form src = https://github.com/staffano/sonbyg git clone https://github.com/staffano/sonbyg dst is the directory that maps to sonbyg.

func Exec

func Exec(id, outDir string, v Variables, cmd string, args ...string)

Exec runs a command and stores the stdout/stderr to a file named <outDir>/<id>.<nr>, where nr is a number that makes the filename unique within the directory.

func FileExists

func FileExists(filename string) bool

FileExists returns true if there is a file at the path

func FileMD5

func FileMD5(path string) []byte

FileMD5 calculates the MD5 sum of a file

func FilenameFromURL

func FilenameFromURL(URL string) string

FilenameFromURL extracts the filename from an URL

func GetUniqueFilename

func GetUniqueFilename(id, outDir string) string

GetUniqueFilename returns a path in the form <outDir>/<id>.<nr>, where the nr is generated in a way to make the path unique.

func Install

func Install(src, dst string, mode os.FileMode)

Install copies stuff from src to dst

func IsDir

func IsDir(p string) bool

IsDir checks if the path is a dir

func PathExists

func PathExists(path string) bool

PathExists returns true if the path exists

func UnpackAssets

func UnpackAssets(dstDir string, assets http.FileSystem) error

UnpackAssets unpacks assets into a destination directory

func UnpackFile

func UnpackFile(filePath string, targetDir string)

UnpackFile ...

func Unzip

func Unzip(src, dest string) error

Unzip ... cf. https://stackoverflow.com/a/24792688

Types

type Variables

type Variables map[string]interface{}

Variables represents a map of variables.

func NewVariables

func NewVariables(vars []string) Variables

NewVariables creates a new Variables object and import the environment variables

func (*Variables) Append

func (v *Variables) Append(vals Variables)

Append a set of variables

func (Variables) AppendEnv

func (v Variables) AppendEnv(env []string) []string

AppendEnv takes an existing env and merges in (overwrites) the variables

func (Variables) Copy

func (v Variables) Copy(keys ...string) Variables

Copy will select the keys from variables and create a new variables. if "all" is specified all variables will be copied.

func (Variables) Dump

func (v Variables) Dump()

Dump prints the variables

func (Variables) ExportEnv

func (v Variables) ExportEnv() []string

ExportEnv exports environment variables in the form "key=val" The value will use the default string conversion of the underlying type

func (Variables) Get

func (v Variables) Get(key string) string

Get will get the resolved value of key

func (*Variables) ImportEnv

func (v *Variables) ImportEnv(env []string)

ImportEnv imports environment variables in the form "key=val"

func (Variables) IsNull

func (v Variables) IsNull() bool

IsNull checks if the variable list is empty

func (Variables) Names

func (v Variables) Names() []string

Names returns a list of all variable name

func (*Variables) PrependEnv

func (v *Variables) PrependEnv(key string, value string)

PrependEnv prepends the value to the variable with key. If the key variable is not an environment list variable, the result is unknown

func (Variables) Printf

func (v Variables) Printf(format string, args ...interface{})

Printf will check the existence of VERBOSE and log accordingly If "DEBUG_BUILD" is set, then all variables will be printed

func (Variables) Resolve

func (v Variables) Resolve(str string) string

Resolve the string and replace all variable references with values from the Variables

func (*Variables) ResolveAll

func (v *Variables) ResolveAll()

ResolveAll will resolve all variable references within Variables

func (*Variables) Set

func (v *Variables) Set(key string, val interface{})

Set the value of the variable

Jump to

Keyboard shortcuts

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