utils

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: Apache-2.0 Imports: 25 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSHA

func CheckSHA(reader io.Reader, sha string) error

CheckSHA returns error if the hash of reader content mismatches `sha`

func CheckSHA256

func CheckSHA256(reader io.Reader, sha string) error

CheckSHA256 returns an error if the hash of reader mismatches `sha`

func Checksum

func Checksum(file string) (string, error)

Checksum returns the sha1 sum of target file

func Copy

func Copy(src, dst string) error

Copy copies a file or directory from src to dst

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies a file from src to dst

func CreateDir

func CreateDir(path string) error

CreateDir creates the directory if it not exists.

func CurrentUser

func CurrentUser() string

CurrentUser returns current login user

func FmtVer

func FmtVer(ver string) (string, error)

FmtVer converts a version string to SemVer format, if the string is not a valid SemVer and fails to parse and convert it, an error is raised.

func GetFreePort

func GetFreePort(host string, priority int) (int, error)

GetFreePort asks the kernel for a free open port that is ready to use.

func IsEmptyDir

func IsEmptyDir(path string) (bool, error)

IsEmptyDir check whether a path is an empty directory

func IsExist

func IsExist(path string) bool

IsExist check whether a path is exist

func IsNotExist

func IsNotExist(path string) bool

IsNotExist check whether a path is not exist

func Move

func Move(src, dst string) error

Move moves a file from src to dst, this is done by copying the file and then delete the old one. Use os.Rename() to rename file within the same filesystem instead this, it's more lightweight but can not be used across devices.

func MustGetFreePort

func MustGetFreePort(host string, priority int) int

MustGetFreePort asks the kernel for a free open port that is ready to use, if fail, panic

func PostFile

func PostFile(reader io.Reader, url, fieldname, filename string) (*http.Response, error)

PostFile upload file

func RebuildArgs

func RebuildArgs(args []string) []string

RebuildArgs move "--help" or "-h" flag to the end of the arg list

func Retry

func Retry(f func() error, when func(error) bool) error

Retry when the when func returns true

func SHA256

func SHA256(reader io.Reader) (string, error)

SHA256 returns the hash of reader

func SHA512

func SHA512(reader io.Reader) (string, error)

SHA512 returns the hash of reader

func Untar

func Untar(reader io.Reader, to string) error

Untar decompresses the tarball

func UserHome

func UserHome() string

UserHome returns home directory of current user

Types

type HTTPClient

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

HTTPClient is a wrap of http.Client

func NewHTTPClient

func NewHTTPClient(timeout time.Duration, tlsConfig *tls.Config) *HTTPClient

NewHTTPClient returns a new HTTP client with timeout and HTTPS support

func (*HTTPClient) Delete

func (c *HTTPClient) Delete(url string, body io.Reader) ([]byte, int, error)

Delete send a DELETE request to the url and returns the response and status code.

func (*HTTPClient) Get

func (c *HTTPClient) Get(url string) ([]byte, error)

Get fetch an URL with GET method and returns the response

func (*HTTPClient) Post

func (c *HTTPClient) Post(url string, body io.Reader) ([]byte, error)

Post send a POST request to the url and returns the response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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