Documentation ¶
Index ¶
- Constants
- Variables
- func CheckSHA256(reader io.Reader, sha string) error
- func Checksum(file string) (string, error)
- func Copy(src, dst string) error
- func CreateDir(path string) error
- func CurrentUser() string
- func FmtVer(ver string) (string, error)
- func GetFreePort(host string, priority int) (int, error)
- func IsEmptyDir(path string) (bool, error)
- func IsExecBinary(path string) bool
- func IsExist(path string) bool
- func IsFlagSetByUser(flagSet *pflag.FlagSet, flagName string) bool
- func IsNotExist(path string) bool
- func IsSubDir(parent, sub string) bool
- func IsSymExist(path string) bool
- func IsTimeoutOrMaxRetry(err error) bool
- func JoinInt(nums []int, delim string) string
- func Move(src, dst string) error
- func MustGetFreePort(host string, priority int) int
- func OpenFileInEditor(filename string) error
- func PostFile(reader io.Reader, url, fieldname, filename string) (*http.Response, error)
- func RebuildArgs(args []string) []string
- func Retry(doFunc func() error, opts ...RetryOption) error
- func RetryUntil(f func() error, when func(error) bool) error
- func SHA256(reader io.Reader) (string, error)
- func SHA512(reader io.Reader) (string, error)
- func ShowDiff(t1 string, t2 string, w io.Writer)
- func TailN(fname string, n int) (lines []string, err error)
- func Untar(reader io.Reader, to string) error
- func UserHome() string
- func ValidateSpecDiff(s1, s2 interface{}) error
- type HTTPClient
- type HashValidationErr
- type RetryOption
- type Version
Constants ¶
const DefaultEditor = "vi"
DefaultEditor is vi because we're adults ;)
const NightlyVersionAlias = "nightly"
NightlyVersionAlias represents latest build of master branch.
Variables ¶
var ( // ErrValidateChecksum is an empty HashValidationErr object, useful for type checking ErrValidateChecksum = &HashValidationErr{} )
Functions ¶
func CheckSHA256 ¶
CheckSHA256 returns an error if the hash of reader mismatches `sha`
func FmtVer ¶
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 ¶
GetFreePort asks the kernel for a free open port that is ready to use.
func IsEmptyDir ¶
IsEmptyDir check whether a path is an empty directory
func IsExecBinary ¶ added in v1.2.0
IsExecBinary check whether a path is a valid executable
func IsFlagSetByUser ¶ added in v1.1.0
IsFlagSetByUser check if the a flag is set by user explicitly
func IsSymExist ¶ added in v1.0.8
IsSymExist check whether a symbol link is exist
func IsTimeoutOrMaxRetry ¶ added in v1.1.0
IsTimeoutOrMaxRetry return true if it's timeout or reach max retry.
func Move ¶
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 ¶
MustGetFreePort asks the kernel for a free open port that is ready to use, if fail, panic
func OpenFileInEditor ¶ added in v1.0.9
OpenFileInEditor opens filename in a text editor.
func RebuildArgs ¶
RebuildArgs move "--help" or "-h" flag to the end of the arg list
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 RetryUntil ¶ added in v1.1.0
RetryUntil when the when func returns true
func ShowDiff ¶ added in v1.0.9
ShowDiff write diff result into the Writer. return false if there's no diff.
func ValidateSpecDiff ¶ added in v1.0.9
func ValidateSpecDiff(s1, s2 interface{}) error
ValidateSpecDiff checks and validates the new spec to see if the modified keys are all marked as editable
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 ¶
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) WithClient ¶ added in v1.4.2
func (c *HTTPClient) WithClient(client *http.Client) *HTTPClient
WithClient uses the specified HTTP client
type HashValidationErr ¶ added in v1.4.0
type HashValidationErr struct {
// contains filtered or unexported fields
}
HashValidationErr is the error indicates a failed hash validation
func (*HashValidationErr) Error ¶ added in v1.4.0
func (e *HashValidationErr) Error() string
Error implements the error interface
func (*HashValidationErr) Is ¶ added in v1.4.0
func (e *HashValidationErr) Is(target error) bool
Is implements the error interface
func (*HashValidationErr) Unwrap ¶ added in v1.4.0
func (e *HashValidationErr) Unwrap() error
Unwrap implements the error interface
type RetryOption ¶ added in v1.1.0
RetryOption is options for Retry()
type Version ¶ added in v1.4.0
type Version string
Version represents a version string, like: v3.1.2