util

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2019 License: MIT Imports: 16 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 GeneratePassword added in v0.0.18

func GeneratePassword(length int) string

GeneratePassword generates a password with the specific length

func Lenf added in v0.0.19

func Lenf(han string) (l int)

Lenf counts the number

func MaxAndMin added in v0.0.21

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

MaxAndMin return the max and min number

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

type HTTPDownloader struct {
	TargetFilePath string
	URL            string
	ShowProgress   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 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 Table

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

Table for console print

func CreateTable

func CreateTable(out io.Writer) Table

CreateTable init a table object

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