utils

package
v0.0.0-...-e107611 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForLines

func ForLines(reader io.Reader, fn func(string) error) error

ForLines runs fn for every line in the provided io.Reader.

func ForLinesInCommandOutput

func ForLinesInCommandOutput(ctx context.Context, cmd []string, fn func(string) error) error

ForLinesInCommandOutput executes a command and runs fn for each line of the stdout.

func ForLinesInFile

func ForLinesInFile(filePath string, fn func(string) error) error

ForLinesInFile runs fn for every line in the provided filePath.

func GenerateServiceCommand

func GenerateServiceCommand(ctx context.Context, serviceName, command string) ([]string, error)

GenerateServiceCommand generates a service command based on the service name and command

func GetTarExtension

func GetTarExtension(tarPath string) string

GetTarExtension returns the extension of a tar file.

func IsNewerVersion

func IsNewerVersion(a, b string) bool

IsNewerVersion returns true if "a" is newer than "b". Only semantic version is accepted (major[.minor[.patch]])

func IsNewerVersionOrEqual

func IsNewerVersionOrEqual(a, b string) bool

IsNewerVersionOrEqual returns true if "a" is newer or equal to "b".

func IsSupportedTarExtension

func IsSupportedTarExtension(tarPath string) bool

IsSupportedTarExtension returns true if the tarPath has a supported extension.

func ListDirectory

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

ListDirectory returns a list of files and directories under the provided dirPath.

func NewCommand

func NewCommand(ctx context.Context, cmd []string) *exec.Cmd

NewCommand creates a new exec.Cmd with the given context and command.

func ParseCommandLine

func ParseCommandLine(command string) ([]string, error)

ParseCommandLine parses a string into an array of commandline arguments

func ParseEnvFile

func ParseEnvFile(filePath string) (map[string]string, error)

ParseEnvFile parses env file into a map of strings.

func RebootCommand

func RebootCommand() ([]string, error)

RebootCommand returns the command to reboot the system

func RunCommand

func RunCommand(ctx context.Context, cmd []string) ([]byte, error)

RunCommand runs a command and returns its output.

func UnpackTar

func UnpackTar(tarPath string, destPath string) error

UnpackTar unpacks a tar archive to a destination directory.

func WriteFileSync

func WriteFileSync(name string, data []byte, perm os.FileMode) error

WriteFileSync writes data to a file named by filename and syncs to disk.

Types

type SemanticVersion

type SemanticVersion [3]uint64

SemanticVersion represents a semantic version (major[.minor[.patch]])

type TailBuffer

type TailBuffer struct {
	// contains filtered or unexported fields
}

TailBuffer keeps a size-limited tail of lines.

func NewTailBuffer

func NewTailBuffer(maxLines int) *TailBuffer

NewTailBuffer returns an initialized TailBuffer for maxLines.

func (*TailBuffer) Close

func (tf *TailBuffer) Close() [][]byte

Close the buffer and return all recorded lines. After calling this method, any writes will result in a panic.

func (*TailBuffer) Push

func (tf *TailBuffer) Push(line []byte)

Push adds a line to the end of the buffer. If buffer is full, the first line of the buffer gets dropped.

func (*TailBuffer) Write

func (tf *TailBuffer) Write(data []byte) (int, error)

Write implements io.Writer for TailBuffer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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