utils

package
v2.4.7 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalidFlow = errors.New("invalid flow")

ErrInvalidFlow returned when parsed flow not valid

View Source
var ErrReadableSizeFormat = errors.New("readable size format invalid")

ErrReadableSizeFormat will return when size format not the same with expected.

View Source
var ErrStoragerTypeInvalid = errors.New("storager type no valid")

ErrStoragerTypeInvalid returned when storager type invalid

Functions

func AlignLinux

func AlignLinux(input ...[]string) [][]string

AlignLinux will align print by lines (element in slice)

func AlignPrintWithColon

func AlignPrintWithColon(s ...string) string

AlignPrintWithColon will align print with ":"

func CalculatePartSize

func CalculatePartSize(size int64) (partSize int64, err error)

CalculatePartSize will calculate the object's part size.

func CheckConfirm

func CheckConfirm(msg string) (bool, error)

CheckConfirm is the public func for confirm check

func DoubleCheckString

func DoubleCheckString(expect, msg string) (bool, error)

DoubleCheckString is the public func for string double check

func IsQsPath added in v2.2.0

func IsQsPath(s string) bool

IsQsPath check whether a path is qingstor path

func NewQingStorService

func NewQingStorService() (storage.Servicer, error)

NewQingStorService will create a new qingstor service.

func NewQingStorStorage

func NewQingStorStorage(pairs ...*typ.Pair) (storage.Storager, error)

NewQingStorStorage will create a new qingstor storage.

func ParseAtServiceInput

func ParseAtServiceInput(t interface {
	types.ServiceSetter
}) (err error)

ParseAtServiceInput will parse single args and setup service.

func ParseAtStorageInput

func ParseAtStorageInput(t interface {
	types.PathSetter
	types.StorageSetter
	types.TypeSetter
}, input string) (dstWorkDir string, err error)

ParseAtStorageInput will parse single args and setup path, type, storager.

func ParseBetweenStorageInput

ParseBetweenStorageInput will parse two args into flow, path and key.

func ParseByteSize

func ParseByteSize(s string) (int64, error)

ParseByteSize will tried to parse string to byte size.

func ParseFlow

func ParseFlow(src, dst string) (flow constants.FlowType)

ParseFlow will parse the data flow

func ParseFsWorkDir

func ParseFsWorkDir(path string) (wd, file string, err error)

ParseFsWorkDir get a path as input, split the work dir and file by following rules 1. if the path is like /path/to/target, parse the wd as /path/to/ and file as target; 2. if the path is like /path/to/, parse the wd as /path/to/ and file as ""; 3. if the path is like . , parse the wd as {pwd}/ and file as "". ParseFsWorkDir use os.PathSeparator as the separator, for capability of windows.

Example
var wd, file string
wd, file, _ = ParseFsWorkDir("/path/to/file")
fmt.Println(fmt.Sprintf("wd: <%s>, file: <%s>", wd, file))

wd, file, _ = ParseFsWorkDir("/path/to/")
fmt.Println(fmt.Sprintf("wd: <%s>, file: <%s>", wd, file))

wd, file, _ = ParseFsWorkDir("/")
fmt.Println(fmt.Sprintf("wd: <%s>, file: <%s>", wd, file))

// wd, file, _ = ParseWorkDir(".")
// fmt.Println(fmt.Sprintf("wd: <%s>, file: <%s>", wd, file))
// Will get --> wd: <{pwd}/>, file: <>

// wd, file, _ = ParseWorkDir("-")
// fmt.Println(fmt.Sprintf("wd: <%s>, file: <%s>", wd, file))
// Will get --> wd: <{pwd}/>, file: <->
Output:

wd: </path/to/>, file: <file>
wd: </path/to/>, file: <>
wd: </>, file: <>

func ParseLocalPath

func ParseLocalPath(p string) (pathType typ.ObjectType, err error)

ParseLocalPath will parse a path into different path type.

func ParseQsPath

func ParseQsPath(p string) (keyType typ.ObjectType, bucketName, objectKey string, err error)

ParseQsPath will parse a key into different key type.

func ParseQsWorkDir

func ParseQsWorkDir(path string) (wd, file string)

ParseQsWorkDir get a path as input, split the work dir and file by like ParseFsWorkDir What's difference is ParseQsWorkDir use '/' as separator, which is defined by qingstor service.

Example
var wd, file string
wd, file = ParseQsWorkDir("/path/to/file")
fmt.Println(fmt.Sprintf("wd: <%s>, file: <%s>", wd, file))

wd, file = ParseQsWorkDir("/path/to/")
fmt.Println(fmt.Sprintf("wd: <%s>, file: <%s>", wd, file))

wd, file = ParseQsWorkDir("/")
fmt.Println(fmt.Sprintf("wd: <%s>, file: <%s>", wd, file))
Output:

wd: </path/to/>, file: <file>
wd: </path/to/>, file: <>
wd: </>, file: <>

func ParseServiceInput

func ParseServiceInput(serviceType StoragerType) (service storage.Servicer, err error)

ParseServiceInput will parse service input.

func ParseStorageInput

func ParseStorageInput(input string, storageType StoragerType) (
	workDir, path string, objectType typ.ObjectType, store storage.Storager, err error)

ParseStorageInput will parse storage input and return a initiated storager.

func UnixReadableSize

func UnixReadableSize(hrSize string) (string, error)

UnixReadableSize will transfer readable size string into Unix size. 1 KB --> 1B, 1.2 GB --> 1.2G, 103 B --> 103B

Types

type ConfirmCheck

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

ConfirmCheck implements ConfirmChecker

func (ConfirmCheck) CheckConfirm

func (c ConfirmCheck) CheckConfirm() (bool, error)

CheckConfirm implements ConfirmChecker.CheckConfirm

type ConfirmChecker

type ConfirmChecker interface {
	CheckConfirm() (bool, error)
}

ConfirmChecker try to confirm return confirmed or not

type InputCheck

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

InputCheck implements StrDoubleChecker

func (InputCheck) DoubleCheckString

func (s InputCheck) DoubleCheckString() (bool, error)

DoubleCheckString implements StrDoubleChecker.DoubleCheckString()

type StoragerType

type StoragerType = string

StoragerType is the alias for the type in storager

type StrDoubleChecker

type StrDoubleChecker interface {
	DoubleCheckString() (bool, error)
}

StrDoubleChecker double check a string and return satisfied or not

Jump to

Keyboard shortcuts

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