utils

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: Apache-2.0 Imports: 25 Imported by: 41

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrShortWrite = errors.New("short write")

Functions

func AsyncMultiWriter added in v0.1.5

func AsyncMultiWriter(writers ...io.Writer) io.Writer

AsyncMultiWriter creates a writer that duplicates its writes to all the provided writers asynchronous

func CalcChecksums added in v0.1.5

func CalcChecksums(reader io.Reader, checksumType ...Algorithm) (map[Algorithm]string, error)

CalcChecksums calculates all hashes at once using AsyncMultiWriter. The file is therefore read only once.

func CleanOldDirs added in v0.1.5

func CleanOldDirs() error

Old runs/tests may leave junk at temp dir. Each temp file/Dir is named with prefix+timestamp, search for all temp files/dirs that match the common prefix and validate their timestamp.

func CreateExtractorPropsFile

func CreateExtractorPropsFile(configPropertiesPath string, configProperties map[string]string) (string, error)

Save all the extractor's properties into a local file. configPropertiesPath - path to a file where all the properties will be written. configProperties - the actual properties.

func CreateTempBuildFile

func CreateTempBuildFile(buildName, buildNumber, projectKey, buildsDirPath string, logger Log) (*os.File, error)

Create a temp file of build-info.

func CreateTempDir added in v0.1.5

func CreateTempDir() (string, error)

CreateTempDir creates a temporary directory and returns its path.

func DoubleWinPathSeparator

func DoubleWinPathSeparator(filePath string) string

func DownloadDependencies

func DownloadDependencies(downloadTo, filename, relativefilePath string, downloadExtractorFunc func(downloadTo, downloadPath string) error, logger Log) error

func DownloadFile

func DownloadFile(downloadTo string, fromUrl string) (err error)

func GetBuildDir

func GetBuildDir(buildName, buildNumber, projectKey, buildsDirPath string) (string, error)

func GetCachePath added in v0.1.5

func GetCachePath() (string, error)

GetCachePath returns the location of downloads dir insied the GOMODCACHE

func GetDependenciesGraph added in v0.1.5

func GetDependenciesGraph(projectDir string, log Log) (map[string][]string, error)

Runs 'go mod graph' command and returns map that maps dependencies to their child dependencies slice

func GetDependenciesList added in v0.1.5

func GetDependenciesList(projectDir string, log Log) (map[string]bool, error)

Runs go list -f {{with .Module}}{{.Path}}:{{.Version}}{{end}} all command and returns map of the dependencies

func GetFileChecksums added in v0.1.5

func GetFileChecksums(filePath string) (checksums *entities.Checksum, err error)

func GetFileContentAndInfo added in v0.1.5

func GetFileContentAndInfo(filePath string) (fileContent []byte, fileInfo os.FileInfo, err error)

func GetGoModCachePath added in v0.1.5

func GetGoModCachePath() (string, error)

GetGoModCachePath returns the location of the go module cache

func GetModuleNameByDir added in v0.1.5

func GetModuleNameByDir(projectDir string, log Log) (string, error)

Runs 'go list -m' command and returns module name

func GetPartialsBuildDir

func GetPartialsBuildDir(buildName, buildNumber, projectKey, buildsDirPath string) (string, error)

func GetProjectRoot added in v0.1.5

func GetProjectRoot() (string, error)

Returns the root dir where the go.mod located.

func IsDirExists

func IsDirExists(path string) (bool, error)

func IsFileExists

func IsFileExists(path string) (bool, error)

func IsPathExists

func IsPathExists(path string) bool

IsPathExists checks if a path exists.

func ListFiles

func ListFiles(path string) ([]string, error)

ListFiles returns a list of files and directories in the specified path

func NewDefaultLogger

func NewDefaultLogger(logLevel LevelType) *defaultLogger

NewDefaultLogger creates a new logger with a given LogLevel. All logs are written to Stderr and output is written to Stdout.

func RemoveTempDir added in v0.1.5

func RemoveTempDir(dirPath string) error

func RunGo added in v0.1.5

func RunGo(goArg []string, repoUrl string) error

Types

type Algorithm added in v0.1.5

type Algorithm int
const (
	MD5 Algorithm = iota
	SHA1
	SHA256
)

type Cmd added in v0.1.5

type Cmd struct {
	Go           string
	Command      []string
	CommandFlags []string
	Dir          string
	StrWriter    io.WriteCloser
	ErrWriter    io.WriteCloser
}

func (*Cmd) GetCmd added in v0.1.5

func (config *Cmd) GetCmd() (cmd *exec.Cmd)

func (*Cmd) GetEnv added in v0.1.5

func (config *Cmd) GetEnv() map[string]string

func (*Cmd) GetErrWriter added in v0.1.5

func (config *Cmd) GetErrWriter() io.WriteCloser

func (*Cmd) GetStdWriter added in v0.1.5

func (config *Cmd) GetStdWriter() io.WriteCloser

type LevelType

type LevelType int
const (
	ERROR LevelType = iota
	WARN
	INFO
	DEBUG
)

type Log

type Log interface {
	Debug(a ...interface{})
	Info(a ...interface{})
	Warn(a ...interface{})
	Error(a ...interface{})
	Output(a ...interface{})
}

type NullLog

type NullLog struct {
}

NullLog is a logger that does nothing

func (*NullLog) Debug

func (nl *NullLog) Debug(...interface{})

func (*NullLog) Error

func (nl *NullLog) Error(...interface{})

func (*NullLog) Info

func (nl *NullLog) Info(...interface{})

func (*NullLog) Output

func (nl *NullLog) Output(...interface{})

func (*NullLog) Warn

func (nl *NullLog) Warn(...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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