Documentation
¶
Index ¶
- Constants
- Variables
- func Base52Decode(encoded string) (int64, error)
- func Base52Encode(id int64) string
- func Base62Tag() string
- func CheckSHA256(reader io.Reader, sha string) error
- func Checksum(file string) (string, error)
- func Copy(src, dst string) error
- func CurrentUser() string
- func FmtVer(ver string) (string, 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 JoinHostPort(host string, port int) string
- func JoinInt(nums []int, delim string) string
- func MatchGroups(r *regexp.Regexp, str string) map[string]string
- func MkdirAll(path string, minPerm os.FileMode) error
- func Move(src, dst string) error
- func MustAtoI(a string) int
- func MustGetFreePort(host string, defaultPort int, portOffset int) int
- func OpenFileInEditor(filename string) error
- func ParseHostPort(hostport string) (host, port string)
- 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 SaveFileWithBackup(path string, data []byte, backupDir string) error
- func ShowDiff(t1 string, t2 string, w io.Writer)
- func TailN(fname string, n int) (lines []string, err error)
- func Tar(writer io.Writer, from string) error
- func Ternary(condition bool, a, b any) any
- func Untar(reader io.Reader, to string) error
- func UserHome() string
- func ValidateSpecDiff(s1, s2 any) error
- func WriteFile(name string, data []byte, perm os.FileMode) error
- type AnyQueue
- type AnySet
- type Constraint
- type HTTPClient
- func (c *HTTPClient) Client() *http.Client
- func (c *HTTPClient) Delete(ctx context.Context, url string, body io.Reader) ([]byte, int, error)
- func (c *HTTPClient) Download(ctx context.Context, url, filePath string) error
- func (c *HTTPClient) Get(ctx context.Context, url string) ([]byte, error)
- func (c *HTTPClient) GetWithStatusCode(ctx context.Context, url string) ([]byte, int, error)
- func (c *HTTPClient) Post(ctx context.Context, url string, body io.Reader) ([]byte, error)
- func (c *HTTPClient) PostWithStatusCode(ctx context.Context, url string, body io.Reader) ([]byte, int, error)
- func (c *HTTPClient) Put(ctx context.Context, url string, body io.Reader) ([]byte, int, error)
- func (c *HTTPClient) SetRequestHeader(key, value string)
- func (c *HTTPClient) WithClient(client *http.Client) *HTTPClient
- type HashValidationErr
- type RetryOption
- type StringSet
- func (s StringSet) Difference(rhs StringSet) StringSet
- func (s StringSet) Exist(val string) bool
- func (s StringSet) Insert(val string)
- func (s StringSet) Intersection(rhs StringSet) StringSet
- func (s StringSet) Join(add StringSet) StringSet
- func (s StringSet) Remove(val string)
- func (s StringSet) Slice() []string
- type TableDisplayer
- type Version
Constants ¶
const DefaultEditor = "vi"
DefaultEditor is vi because we're adults ;)
const LatestVersionAlias = "latest"
LatestVersionAlias represents the latest build (excluding nightly versions).
const NextgenVersionAlias = "nextgen"
NextgenVersionAlias represents latest build of nextgen branch.
const NightlyVersionAlias = "nightly"
NightlyVersionAlias represents latest build of master branch.
Variables ¶
var ( // ErrPropSuggestion is a property of an Error that will be printed as the suggestion. ErrPropSuggestion = errorx.RegisterProperty("suggestion") // ErrTraitPreCheck means that the Error is a pre-check error so that no error logs will be outputted directly. ErrTraitPreCheck = errorx.RegisterTrait("pre_check") )
var ( // ErrValidateChecksum is an empty HashValidationErr object, useful for type checking ErrValidateChecksum = &HashValidationErr{} )
Functions ¶
func Base52Decode ¶ added in v0.2.1
Decode will decode the string and return the id The input string should be a valid one with only characters in the space
func Base52Encode ¶ added in v0.2.1
Encode returns a string by encoding the id over a 51 characters space
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 IsEmptyDir ¶
IsEmptyDir check whether a path is an empty directory
func IsExecBinary ¶
IsExecBinary check whether a path is a valid executable
func IsFlagSetByUser ¶
IsFlagSetByUser check if the a flag is set by user explicitly
func IsTimeoutOrMaxRetry ¶
IsTimeoutOrMaxRetry return true if it's timeout or reach max retry.
func JoinHostPort ¶
JoinHostPort return host and port
func MatchGroups ¶
MatchGroups turns a slice of matched string to a map according to capture group name
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 ¶
OpenFileInEditor opens filename in a text editor.
func ParseHostPort ¶
ParseHostPort Prase host and port
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 ¶
RetryUntil when the when func returns true
func SaveFileWithBackup ¶
SaveFileWithBackup will backup the file before save it. e.g., backup meta.yaml as meta-2006-01-02T15:04:05Z07:00.yaml backup the files in the same dir of path if backupDir is empty.
func ValidateSpecDiff ¶
ValidateSpecDiff checks and validates the new spec to see if the modified keys are all marked as editable
Types ¶
type AnyQueue ¶
type AnyQueue struct {
// contains filtered or unexported fields
}
AnyQueue is a queue stores any
func NewAnyQueue ¶
NewAnyQueue builds a AnyQueue
type AnySet ¶
type AnySet struct {
// contains filtered or unexported fields
}
AnySet is a set stores any
func (*AnySet) Difference ¶
Difference returns the difference of two sets
func (*AnySet) Intersection ¶
Intersection returns the intersection of two sets
type Constraint ¶
type Constraint struct {
// contains filtered or unexported fields
}
Constraint for semver
func NewConstraint ¶
func NewConstraint(raw string) (*Constraint, error)
NewConstraint creates a constraint to check whether a semver is valid. Only support ^ and ~ and x|X|*
func (*Constraint) Check ¶
func (c *Constraint) Check(v string) bool
Check checks whether a version is satisfies the constraint
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) Client ¶
func (c *HTTPClient) Client() *http.Client
Client returns the http.Client
func (*HTTPClient) Delete ¶
Delete send a DELETE request to the url and returns the response and status code.
func (*HTTPClient) Download ¶
func (c *HTTPClient) Download(ctx context.Context, url, filePath string) error
Download fetch an URL with GET method and Download the response to filePath
func (*HTTPClient) GetWithStatusCode ¶
GetWithStatusCode fetch a URL with GET method and returns the response, also the status code.
func (*HTTPClient) PostWithStatusCode ¶
func (c *HTTPClient) PostWithStatusCode(ctx context.Context, url string, body io.Reader) ([]byte, int, error)
PostWithStatusCode send a POST request to the url and returns the response, also the http status code.
func (*HTTPClient) Put ¶
Put send a PUT request to the url and returns the response, also the status code
func (*HTTPClient) SetRequestHeader ¶
func (c *HTTPClient) SetRequestHeader(key, value string)
SetRequestHeader set http request header
func (*HTTPClient) WithClient ¶
func (c *HTTPClient) WithClient(client *http.Client) *HTTPClient
WithClient uses the specified HTTP client
type HashValidationErr ¶
type HashValidationErr struct {
// contains filtered or unexported fields
}
HashValidationErr is the error indicates a failed hash validation
func (*HashValidationErr) Error ¶
func (e *HashValidationErr) Error() string
Error implements the error interface
func (*HashValidationErr) Is ¶
func (e *HashValidationErr) Is(target error) bool
Is implements the error interface
func (*HashValidationErr) Unwrap ¶
func (e *HashValidationErr) Unwrap() error
Unwrap implements the error interface
type RetryOption ¶
RetryOption is options for Retry()
type StringSet ¶
type StringSet map[string]struct{}
StringSet is a string set.
func (StringSet) Difference ¶
Difference returns the difference of two sets
func (StringSet) Intersection ¶
Intersection returns the intersection of two sets
type TableDisplayer ¶
TableDisplayer is a simple table displayer
func NewTableDisplayer ¶
func NewTableDisplayer(w io.Writer, header []string) *TableDisplayer
NewTableDisplayer creates a new TableDisplayer
func (*TableDisplayer) AddRow ¶
func (t *TableDisplayer) AddRow(row ...string)
AddRow adds a row to the table
type Version ¶
type Version string
Version represents a version string, like: v3.1.2