util

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(argv0 string, argv []string, envv []string, systemCallExec SystemCallExec) error

Exec is the wrapper of syscall.Exec

func ExecCommand

func ExecCommand(context ExecContext, name string, arg ...string) *exec.Cmd

ExecCommand is a warp of exec.Command

func FakeExecCommandSuccess

func FakeExecCommandSuccess(command string, args ...string) *exec.Cmd

FakeExecCommandSuccess is a function that initialises a new exec.Cmd, one which will simply call TestShellProcessSuccess rather than the command it is provided. It will also pass through the command and its arguments as an argument to TestShellProcessSuccess

func FakeLookPath

func FakeLookPath(path string) (string, error)

FakeLookPath is a fake function of exec.LookPath

func FakeSystemCallExecSuccess

func FakeSystemCallExecSuccess(argv0 string, argv []string, envv []string) (err error)

FakeSystemCallExecSuccess is a fake function of syscall.Exec

func GeneratePassword

func GeneratePassword(length int) string

GeneratePassword generates a password with the specific length

func GetEnvOrDefault

func GetEnvOrDefault(key, defaultVal string) (result string)

GetEnvOrDefault returns a env or default value

func InitLogger

func InitLogger(level string) (logger *zap.Logger, err error)

InitLogger returns a logger

func LookPath

func LookPath(file string, context LookPathContext) (string, error)

LookPath is the wrapper of exec.LookPath

func MaxAndMin

func MaxAndMin(data []float64) (max, min float64)

MaxAndMin return the max and min number

func Open

func Open(url string, browser string, cmdContext ExecContext) error

Open a URL in a browser

func PrintCollectTrend

func PrintCollectTrend(data []float64) (buf string)

PrintCollectTrend print the trend of data

func ReadFile added in v0.0.14

func ReadFile(file string) (data []byte)

ReadFile reads the content of a file, returns it as byte slice

func ReadFileASString added in v0.0.14

func ReadFileASString(file string) string

ReadFileASString reads the content of a file, returns it as string

func TOJSON added in v0.0.14

func TOJSON(data interface{}) (result string)

TOJSON convert an interface as JSON string

func URLJoin

func URLJoin(host, api string) (targetURL *url.URL, err error)

URLJoin is a util function to join host URL and API URL

func URLJoinAsString

func URLJoinAsString(host, api string) (targetURLStr string, err error)

URLJoinAsString is an util function to join host URL and API URL

Types

type ExecContext

type ExecContext = func(name string, arg ...string) *exec.Cmd

ExecContext is the context of system command caller

type LookPathContext

type LookPathContext = func(file string) (string, error)

LookPathContext is the context of look path

type SystemCallExec

type SystemCallExec = func(argv0 string, argv []string, envv []string) (err error)

SystemCallExec is the context of syscall.Exec

Jump to

Keyboard shortcuts

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