utils

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrTopologyReadFailed is ErrTopologyReadFailed
	ErrTopologyReadFailed = errNSTopolohy.NewType("read_failed", errutil.ErrTraitPreCheck)
	// ErrTopologyParseFailed is ErrTopologyParseFailed
	ErrTopologyParseFailed = errNSTopolohy.NewType("parse_failed", errutil.ErrTraitPreCheck)
)
View Source
var (
	// ErrInvalidClusterName is an error for invalid cluster name. You should use `ValidateClusterNameOrError()`
	// to generate this error.
	ErrInvalidClusterName = errorx.CommonErrors.NewType("invalid_cluster_name", errutil.ErrTraitPreCheck)
)

Functions

func Checksum added in v0.4.9

func Checksum(file string) (string, error)

Checksum returns the sha1 sum of target file

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

func CurrentUser() string

CurrentUser returns current login user

func IsTimeoutOrMaxRetry added in v0.5.0

func IsTimeoutOrMaxRetry(err error) bool

IsTimeoutOrMaxRetry return true if it's timeout or reach max retry.

func JoinInt

func JoinInt(nums []int, delim string) string

JoinInt joins a slice of int to string

func Move

func Move(src, dst string) error

Move moves a file or directory from src to dst

func ParseTopologyYaml

func ParseTopologyYaml(file string, out interface{}) error

ParseTopologyYaml read yaml content from `file` and unmarshal it to `out`

func Retry

func Retry(doFunc func() error, opts ...RetryOption) error

Retry retries the func until it returns no error or reaches attempts limit or timed out, either one is earlier

func UserHome added in v0.6.0

func UserHome() string

UserHome returns home directory of current user

func ValidateClusterNameOrError

func ValidateClusterNameOrError(n string) error

ValidateClusterNameOrError validates a cluster name and returns error if the name is invalid.

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

type RetryOption

type RetryOption struct {
	Attempts int64
	Delay    time.Duration
	Timeout  time.Duration
}

RetryOption is options for Retry()

Jump to

Keyboard shortcuts

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