util

package
v0.0.0-...-a1f8bd1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultConsoleReader ConsoleReader = StdinConsoleReader{}
	DefaultConsoleWriter ConsoleWriter = StdoutConsoleWriter{}
)

Functions

func AddIfNotExist

func AddIfNotExist(values []string, value string) []string

func CopyMap

func CopyMap(m map[string]interface{}) map[string]interface{}

func CopyStringMap

func CopyStringMap(m map[string]string) map[string]string

func GetValue

func GetValue(key string, value interface{}) (res interface{}, err error)

GetValue allows to extract value from the provided object by the "path" inside of its structure Example:

		With the following object: map[string]interface{}{"a": map[string]interface{}{"b": "c"}}
     the value "c" can be reached by "a.b.c"

func Lookup

func Lookup(command string) (string, error)

Lookup returns path to command

func MapErr

func MapErr[T any, R any](collection []T, iteratee func(T, int) (R, error)) ([]R, error)

MapErr is similar to lo.Map, but handles error in iteratee function

func MultiWriteCloser

func MultiWriteCloser(wc ...io.WriteCloser) io.WriteCloser

MultiWriteCloser multiWriteCloser creates a WriteCloser that duplicates its writes and closes to all the provided writers.

func NewLineOrReturnScanner

func NewLineOrReturnScanner(reader io.Reader) *bufio.Scanner

func ReaderToBufFunc

func ReaderToBufFunc(reader io.Reader, buf *bytes.Buffer) func() error

ReaderToBufFunc returns function that should be called in a goroutine. It reads lines from a provided reader and writes each one into the provided buffer

func ReaderToCallbackFunc

func ReaderToCallbackFunc(ctx context.Context, reader io.Reader, callback func(string)) func() error

ReaderToCallbackFunc returns function that is meant to be called from a separate goroutine function starts streaming from reader to logger and appends extra prefix to each line

func ReaderToLogFunc

func ReaderToLogFunc(reader io.Reader, logToErr bool, prefix string, logger Logger, subject string) func() error

ReaderToLogFunc returns function that is meant to be called from a separate goroutine function starts streaming from reader to logger and appends extra prefix to each line

func SafeSplit

func SafeSplit(s string) []string

func ScanNewLineOrReturn

func ScanNewLineOrReturn(data []byte, atEOF bool) (advance int, token []byte, err error)

func ToEnvVariableName

func ToEnvVariableName(str string) string

func ToObjectViaJson

func ToObjectViaJson[T any](from any, to *T) (*T, error)

func ToSnakeCase

func ToSnakeCase(str string) string

func TrimStringMiddle

func TrimStringMiddle(str string, maxLen int, sep string) string

Types

type Console

type Console interface {
	AskYesNoQuestionWithDefault(question string, yes bool) (bool, error)
	AskQuestionWithDefault(question string, defaultResponse string) (string, error)
	AskQuestion(question string) (string, error)
	Writer() ConsoleWriter
	Reader() ConsoleReader
	SetReader(reader ConsoleReader)
	SetWriter(writer ConsoleWriter)
}

type ConsoleImpl

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

func NewDefaultConsole

func NewDefaultConsole() *ConsoleImpl

func (*ConsoleImpl) AlwaysRespondDefault

func (c *ConsoleImpl) AlwaysRespondDefault() *ConsoleImpl

func (*ConsoleImpl) AskQuestion

func (c *ConsoleImpl) AskQuestion(question string) (string, error)

func (*ConsoleImpl) AskQuestionWithDefault

func (c *ConsoleImpl) AskQuestionWithDefault(question string, defaultResponse string) (string, error)

func (*ConsoleImpl) AskYesNoQuestionWithDefault

func (c *ConsoleImpl) AskYesNoQuestionWithDefault(question string, yes bool) (bool, error)

func (*ConsoleImpl) Reader

func (c *ConsoleImpl) Reader() ConsoleReader

func (*ConsoleImpl) SetReader

func (c *ConsoleImpl) SetReader(reader ConsoleReader)

func (*ConsoleImpl) SetWriter

func (c *ConsoleImpl) SetWriter(writer ConsoleWriter)

func (*ConsoleImpl) Writer

func (c *ConsoleImpl) Writer() ConsoleWriter

type ConsoleReader

type ConsoleReader interface {
	ReadLine() (string, error)
	ReadPassword() (string, error)
}

type ConsoleWriter

type ConsoleWriter interface {
	Print(args ...interface{})
	Println(args ...interface{})
}

type Data

type Data map[string]interface{}

func (Data) AddAllIfNotExist

func (data Data) AddAllIfNotExist(other Data)

type Exec

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

Exec defines execution on host environment

func NewExec

func NewExec(context context.Context, logger Logger) Exec

NewExec initializes new host executor

func NewExecWithOutput

func NewExecWithOutput(context context.Context, logger Logger, output *bytes.Buffer) Exec

NewExecWithOutput initializes new host executor

func (*Exec) ExecCommand

func (e *Exec) ExecCommand(cmd string, opts ExecOpts) (string, error)

ExecCommand executes command and returns output

func (*Exec) ExecCommandAndLog

func (e *Exec) ExecCommandAndLog(subject string, cmd string, opts ExecOpts) (ExecRes, error)

ExecCommandAndLog executes command and logs into the provided logger

func (*Exec) ProxyExec

func (e *Exec) ProxyExec(cmd string, opts ExecOpts) error

ProxyExec executes command with all binding to parent process

type ExecOpts

type ExecOpts struct {
	Wd  string
	Env []string
}

ExecOpts execution options

type ExecRes

type ExecRes struct {
	Pid int
	Env []string
}

ExecRes result of execution

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})

	Log(msg string)

	Logf(format string, args ...interface{})

	Err(msg string)

	Errf(format string, args ...interface{})

	SubLogger(name string) Logger
}

type NoopLogger

type NoopLogger struct{}

func (*NoopLogger) Debugf

func (l *NoopLogger) Debugf(format string, msg ...interface{})

func (*NoopLogger) Err

func (l *NoopLogger) Err(msg string)

func (*NoopLogger) Errf

func (l *NoopLogger) Errf(format string, msg ...interface{})

func (*NoopLogger) Log

func (l *NoopLogger) Log(msg string)

func (*NoopLogger) Logf

func (l *NoopLogger) Logf(format string, msg ...interface{})

func (*NoopLogger) SubLogger

func (l *NoopLogger) SubLogger(name string) Logger

type PrefixLogger

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

func (*PrefixLogger) Debugf

func (l *PrefixLogger) Debugf(format string, msg ...interface{})

func (*PrefixLogger) Err

func (l *PrefixLogger) Err(msg string)

func (*PrefixLogger) Errf

func (l *PrefixLogger) Errf(format string, msg ...interface{})

func (*PrefixLogger) Log

func (l *PrefixLogger) Log(msg string)

func (*PrefixLogger) Logf

func (l *PrefixLogger) Logf(format string, msg ...interface{})

func (*PrefixLogger) SubLogger

func (l *PrefixLogger) SubLogger(name string) Logger

func (*PrefixLogger) WithTimeFormat

func (l *PrefixLogger) WithTimeFormat(format string) *PrefixLogger

type StdinConsoleReader

type StdinConsoleReader struct{}

func (StdinConsoleReader) ReadLine

func (reader StdinConsoleReader) ReadLine() (string, error)

func (StdinConsoleReader) ReadPassword

func (reader StdinConsoleReader) ReadPassword() (string, error)

type StdoutConsoleWriter

type StdoutConsoleWriter struct{}

func (StdoutConsoleWriter) Print

func (w StdoutConsoleWriter) Print(args ...interface{})

func (StdoutConsoleWriter) Println

func (w StdoutConsoleWriter) Println(args ...interface{})

type StdoutLogger

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

func NewStdoutLogger

func NewStdoutLogger(stdout io.WriteCloser, stderr io.WriteCloser) *StdoutLogger

func (*StdoutLogger) Debug

func (l *StdoutLogger) Debug() *StdoutLogger

func (*StdoutLogger) Debugf

func (l *StdoutLogger) Debugf(format string, msg ...interface{})

func (*StdoutLogger) Err

func (l *StdoutLogger) Err(msg string)

func (*StdoutLogger) Errf

func (l *StdoutLogger) Errf(format string, msg ...interface{})

func (*StdoutLogger) Log

func (l *StdoutLogger) Log(msg string)

func (*StdoutLogger) Logf

func (l *StdoutLogger) Logf(format string, msg ...interface{})

func (*StdoutLogger) SubLogger

func (l *StdoutLogger) SubLogger(name string) Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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