Documentation ¶
Index ¶
- Variables
- func CMD(cwd string, command string, args ...string) errordeprecated
- func CopyDir(src, dst string) error
- func CopyFile(src, dst string) error
- func DirExists(path string) bool
- func FileExists(path string) bool
- func FindGitRepoRoot() (string, error)
- func GetGitRootDir() (string, error)
- func InitZeroLog(options ...logOption)
- func MoveDir(src, dst string) error
- func MoveFile(src, dst string) error
- func PathExists(path string) bool
- func ReadJSON[T any](filename string, data *T) error
- func ReadText(filename string) (string, error)
- func TimeStrMilliSec() string
- func TimeStrSec() string
- func UUID4() string
- func WriteJSON(filename string, data interface{}) error
- func WriteText(filename, content string) error
- type ExecOptions
- type ExecResult
- type ExecutedHandlerContext
- type PreExecHandlerContext
- type WithCwd
- type WithDumpOutput
- type WithEnv
- type WithExeParentDir
- type WithExecutedHandlerErrorLog
- type WithExecutedHandlerFatalLog
- type WithExecutedHandlerSlient
- type WithLogger
- type WithNoColor
- type WithPreExecLog
- type WithPreExecSlient
- type WithProduction
- type WithWorkDirCmd
Constants ¶
This section is empty.
Variables ¶
var CommandLogger = Logger.With().Str("module", "goutils.command").Logger()
var ExecOpt = &ExecOptions{ Cwd: "", DumpOutput: false, PreExecHandler: preExecHandlerLog, ExecutedHandler: executedHandlerFatalLog, }
ExecOpt is the default options for Exec
var Logger = log.With().Str("module", "goutils").Logger()
Functions ¶
func FileExists ¶
func FindGitRepoRoot ¶
FindGitRepoRoot returns the root directory of the git repository
func GetGitRootDir ¶
GetGitRootDir returns the root directory of the git repository Deprecated: Use FindGitRepoRoot instead
func InitZeroLog ¶
func InitZeroLog(options ...logOption)
func TimeStrMilliSec ¶
func TimeStrMilliSec() string
TimeStrMilliSec returns the time format string with millisecond, like 20240915.221219.123
func TimeStrSec ¶
func TimeStrSec() string
TimeStrSec returns the time format string, like 20240915.221219
Types ¶
type ExecOptions ¶
type ExecOptions struct { // Cwd is the working directory of the command. If empty, the current working directory is used. Cwd string // DumpOutput indicates whether to dump the output to the standard output. DumpOutput bool PreExecHandler func(*PreExecHandlerContext) ExecutedHandler func(*ExecutedHandlerContext) Env map[string]string }
type ExecResult ¶
type ExecResult struct { Stdout string Stderr string // Output is the combined stdout and stderr Output string }
ExecResult is the result of the command
func Exec ¶
func Exec(cmd string, opts ...execOption) (*ExecResult, error)
Exec is a wrapper of exec.Command.
Parameters: - cmd: the command to run, e.g. "ls -l". Spaces are used to split the command and arguments. Shell features like pipes are not supported. - opts: options to customize the behavior of the command
Returns: - *ExecResult: the result of the command. Always not nil. Even if the command fails, the result may contain some output. - error: if the command fails
type ExecutedHandlerContext ¶
type ExecutedHandlerContext struct { Cmd string Opt *ExecOptions Res *ExecResult Err error }
type PreExecHandlerContext ¶
type PreExecHandlerContext struct { Cmd string Opt *ExecOptions }
type WithDumpOutput ¶
type WithDumpOutput struct { }
type WithExeParentDir ¶
type WithExeParentDir struct { }
WithExeParentDir is a option to set the working directory to the parent directory of the executable
type WithExecutedHandlerErrorLog ¶
type WithExecutedHandlerErrorLog struct { }
type WithExecutedHandlerFatalLog ¶
type WithExecutedHandlerFatalLog struct { }
type WithExecutedHandlerSlient ¶
type WithExecutedHandlerSlient struct { }
type WithLogger ¶
type WithNoColor ¶
type WithNoColor struct { }
type WithPreExecLog ¶
type WithPreExecLog struct { }
type WithPreExecSlient ¶
type WithPreExecSlient struct { }
type WithProduction ¶
type WithProduction struct { DirLog string FileName string Append bool // Append to existing log file, if false, it will overwrite the existing log file. }
WithProduction is a log option, which is aimed to be used in production environment.
type WithWorkDirCmd ¶
type WithWorkDirCmd struct { }