util

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: MIT Imports: 23 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ContentType is for the http header of content type
	ContentType = "Content-Type"
	// ApplicationForm is for the form submit
	ApplicationForm = "application/x-www-form-urlencoded"
)
View Source
const (
	// AlignLeft align left
	AlignLeft = 0
	// AlignCenter align center
	AlignCenter = 1
	// AlignRight align right
	AlignRight = 2
)

Variables

This section is empty.

Functions

func Exec added in v0.0.24

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

Exec is the wrapper of syscall.Exec

func ExecCommand added in v0.0.24

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

ExecCommand is a warp of exec.Command

func FakeExecCommandSuccess added in v0.0.24

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 added in v0.0.24

func FakeLookPath(path string) (string, error)

FakeLookPath is a fake function of exec.LookPath

func FakeSystemCallExecSuccess added in v0.0.24

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

FakeSystemCallExecSuccess is a fake function of syscall.Exec

func GeneratePassword added in v0.0.18

func GeneratePassword(length int) string

GeneratePassword generates a password with the specific length

func InitLogger added in v0.0.23

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

InitLogger returns a logger

func Lenf added in v0.0.19

func Lenf(han string) (l int)

Lenf counts the number

func LookPath added in v0.0.24

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

LookPath is the wrapper of exec.LookPath

func MaxAndMin added in v0.0.21

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

MaxAndMin return the max and min number

func Open added in v0.0.24

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

Open a URL in a browser

func Pad

func Pad(s, pad string, width int, align int) string

Pad give a pad

func PadCenter

func PadCenter(s, pad string, width int) string

PadCenter pad as center

func PadLeft

func PadLeft(s, pad string, width int) string

PadLeft pad as left

func PadRight

func PadRight(s, pad string, width int) string

PadRight pas as right

func PrintCollectTrend added in v0.0.21

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

PrintCollectTrend print the trend of data

func ReflectFieldValueAsString added in v0.0.24

func ReflectFieldValueAsString(v reflect.Value, field string) string

ReflectFieldValueAsString returns the value of a field

func SetProxy added in v0.0.21

func SetProxy(proxy, proxyAuth string, tr *http.Transport) (err error)

SetProxy set the proxy for a http

Types

type ExecContext added in v0.0.24

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

ExecContext is the context of system command caller

type HTTPDownloader added in v0.0.18

type HTTPDownloader struct {
	TargetFilePath     string
	URL                string
	ShowProgress       bool
	InsecureSkipVerify bool

	UserName string
	Password string

	Proxy     string
	ProxyAuth string

	Debug        bool
	RoundTripper http.RoundTripper
}

HTTPDownloader is the downloader for http request

func (*HTTPDownloader) DownloadFile added in v0.0.18

func (h *HTTPDownloader) DownloadFile() error

DownloadFile download a file with the progress

type LookPathContext added in v0.0.24

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

LookPathContext is the context of look path

type ProgressIndicator added in v0.0.18

type ProgressIndicator struct {
	Writer io.Writer
	Reader io.Reader
	Title  string

	// bytes.Buffer
	Total float64
	// contains filtered or unexported fields
}

ProgressIndicator hold the progress of io operation

func (*ProgressIndicator) Init added in v0.0.18

func (i *ProgressIndicator) Init()

Init set the default value for progress indicator

func (*ProgressIndicator) Read added in v0.0.18

func (i *ProgressIndicator) Read(p []byte) (n int, err error)

Read reads the progress

func (*ProgressIndicator) Write added in v0.0.18

func (i *ProgressIndicator) Write(p []byte) (n int, err error)

Write writes the progress

type SystemCallExec added in v0.0.24

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

SystemCallExec is the context of syscall.Exec

type Table

type Table struct {
	Out          io.Writer
	Rows         [][]string
	ColumnWidths []int
	ColumnAlign  []int
	Separator    string

	WithHeader bool
}

Table for console print

func CreateTable

func CreateTable(out io.Writer) Table

CreateTable init a table object

func CreateTableWithHeader added in v0.0.23

func CreateTableWithHeader(out io.Writer, withoutHeader bool) (table Table)

CreateTableWithHeader init a table object

func (*Table) AddHeader added in v0.0.23

func (t *Table) AddHeader(col ...string)

AddHeader adds a header to the table

func (*Table) AddRow

func (t *Table) AddRow(col ...string)

AddRow adds a new row to the table

func (*Table) Clear

func (t *Table) Clear()

Clear removes all rows while preserving the layout

func (*Table) GetColumnAlign

func (t *Table) GetColumnAlign(i int) int

GetColumnAlign return the column alignment

func (*Table) Render

func (t *Table) Render()

Render render the table into byte array

func (*Table) SetColumnAlign

func (t *Table) SetColumnAlign(i int, align int)

SetColumnAlign sets the column alignment for the given column index

func (*Table) SetColumnsAligns

func (t *Table) SetColumnsAligns(colAligns []int)

SetColumnsAligns sets the alignment of the columns

Jump to

Keyboard shortcuts

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