util

package
v0.0.0-...-13a05f4 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_BAR_LENGTH = 30
	BAR_TYPE       = "#"
)
View Source
const (
	BOS_PATH_SEPARATOR = "/"
)
View Source
const (
	Separator = os.PathSeparator
)

Variables

View Source
var ErrBadPattern = errors.New("syntax error in pattern")

ErrBadPattern indicates a globbing pattern was malformed.

View Source
var (
	OsPathSeparator = fmt.Sprintf("%c", os.PathSeparator)
)

Functions

func Abs

func Abs(localPath string) (string, error)

Wrapper of function filepath.Abs() Abs can recognize '~'

func CreateAnRandomFileWithContent

func CreateAnRandomFileWithContent(format string, args ...interface{}) (*os.File, string, error)

create a temp file and write content to this file

func CreateFileWithSize

func CreateFileWithSize(filePath string, fileSize int64) error

func DoesDirExist

func DoesDirExist(fileFolder string) bool

Check whether directory exist.

func DoesFileExist

func DoesFileExist(filePath string) bool

Check whether file path exist.

func DoesPathExist

func DoesPathExist(filePath string) bool

Check whether path exist

func ErrorEqual

func ErrorEqual(funcName string, id int, alert func(format string, args ...interface{}), expected,
	actual interface{}) bool

func ExpectEqual

func ExpectEqual(funcName string, id int, alert func(format string, args ...interface{}), expected,
	actual interface{}) bool

func FilterSpace

func FilterSpace(components []string) []string

Fileter array

func GetFileMd5

func GetFileMd5(fd *os.File, offset, size int64, whence int) (string, error)

calc the md5 of local file whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end

func GetHomeDirOfUser

func GetHomeDirOfUser() (string, error)

Geting home directory of current user

func GetHostFromUrl

func GetHostFromUrl(useUrl string) (string, error)

Get host name from url

func GetParentPath

func GetParentPath(lists []string, upLevel int) string

func GetRandomString

func GetRandomString(size int64) string

Generate a random string

func GetSizeOfFile

func GetSizeOfFile(filePath string) (int64, error)

Geting the size of file.

func InitTestFiles

func InitTestFiles()

func IsDirWritable

func IsDirWritable(fileFolder string) bool

check dir is writable TODO: have more efficient method?

func IsFileWritable

func IsFileWritable(filePath string) bool

check file is writable

func IsSymbolicLink(filePath string) (bool, error)

check whether file is symbolic link

func Match

func Match(pattern, name string) (matched bool, err error)

Match reports whether name matches the shell file name pattern. The pattern syntax is:

pattern:
	{ term }
term:
	'*'         matches any sequence
	'?'         matches any single character
	'[' [ '^' ] { character-range } ']'
	            character class (must be non-empty)
	c           matches character c (c != '*', '?', '\\', '[')
	'\\' c      matches character c

character-range:
	c           matches character c (c != '\\', '-', ']')
	'\\' c      matches character c
	lo '-' hi   matches character c for lo <= c <= hi

Match requires pattern to match all of name, not just a substring. The only possible returned error is ErrBadPattern, when pattern is malformed.

On Windows, escaping is disabled. Instead, '\\' is treated as path separator.

func PrintWaiting

func PrintWaiting(propmt string, stop chan bool)

Provide dynamic waiting propmt. stop: send signal to stop PrintWaiting

func PromptConfirm

func PromptConfirm(format string, args ...interface{}) bool

func ReadSortedDirNames

func ReadSortedDirNames(localPath string) ([]string, error)

Get sorted files and dir names from dir

func StringMd5

func StringMd5(strVal string) string

Get md5 of string

func TranTimestamptoLocalTime

func TranTimestamptoLocalTime(timestamp int64, newTimeForm string) string

Change timestamp to local time

func TranUTCTimeStringToTimeStamp

func TranUTCTimeStringToTimeStamp(utcTimeString, oldTimeForm string) (int64, error)

Change UTC time string to timestamp

func TranUTCtoLocalTime

func TranUTCtoLocalTime(utcTimeString, oldTimeForm, newTimeForm string) (string, error)

Change UTC time string to local time string

func TryMkdir

func TryMkdir(pathToMake string) error

try to mkdir

Types

type Bar

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

func NewBar

func NewBar(total int, prefix string, quiet bool) (*Bar, error)

func (*Bar) Exit

func (b *Bar) Exit() error

func (*Bar) Finish

func (b *Bar) Finish(num int)

func (*Bar) GetId

func (b *Bar) GetId() (string, error)

type CompleteFuncInter

type CompleteFuncInter interface {
	Exit() error
	GetId() (string, error)
}

type Finisher

type Finisher struct {
	// contains filtered or unexported fields
}
var (
	GFinisher *Finisher
)

func (*Finisher) Clear

func (f *Finisher) Clear()

func (*Finisher) Execute

func (f *Finisher) Execute() error

func (*Finisher) Insert

func (f *Finisher) Insert(finsher CompleteFuncInter) error

func (*Finisher) Remove

func (f *Finisher) Remove(finsher CompleteFuncInter) error

Jump to

Keyboard shortcuts

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