overdue
This commit is contained in:
17
.rclone_repo/vendor/github.com/pengsrc/go-shared/check/dir.go
generated
vendored
Executable file
17
.rclone_repo/vendor/github.com/pengsrc/go-shared/check/dir.go
generated
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Dir checks the given path, will return error if path not exists or path
|
||||
// is not directory.
|
||||
func Dir(path string) error {
|
||||
if info, err := os.Stat(path); err != nil {
|
||||
return fmt.Errorf(`directory not exists: %s`, path)
|
||||
} else if !info.IsDir() {
|
||||
return fmt.Errorf(`path is not directory: %s`, path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
37
.rclone_repo/vendor/github.com/pengsrc/go-shared/check/error.go
generated
vendored
Executable file
37
.rclone_repo/vendor/github.com/pengsrc/go-shared/check/error.go
generated
vendored
Executable file
@@ -0,0 +1,37 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// ReadableError is just a structure contains readable message that can be
|
||||
// returned directly to end user.
|
||||
type ReadableError struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
// Error returns the description of ReadableError.
|
||||
func (e ReadableError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
// NewReadableError creates a ReadableError{} from given message.
|
||||
func NewReadableError(message string) ReadableError {
|
||||
return ReadableError{Message: message}
|
||||
}
|
||||
|
||||
// ErrorForExit check the error.
|
||||
// If error is not nil, print the error message and exit the application.
|
||||
// If error is nil, do nothing.
|
||||
func ErrorForExit(name string, err error, code ...int) {
|
||||
if err != nil {
|
||||
exitCode := 1
|
||||
if len(code) > 0 {
|
||||
exitCode = code[0]
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "%s: %s (%d)\n", name, err.Error(), exitCode)
|
||||
fmt.Fprintf(os.Stderr, "See \"%s --help\".\n", name)
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
}
|
||||
11
.rclone_repo/vendor/github.com/pengsrc/go-shared/check/host.go
generated
vendored
Executable file
11
.rclone_repo/vendor/github.com/pengsrc/go-shared/check/host.go
generated
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// HostAndPort checks whether a string contains host and port.
|
||||
// It returns true if matched.
|
||||
func HostAndPort(hostAndPort string) bool {
|
||||
return regexp.MustCompile(`^[^:]+:[0-9]+$`).MatchString(hostAndPort)
|
||||
}
|
||||
41
.rclone_repo/vendor/github.com/pengsrc/go-shared/check/slice.go
generated
vendored
Executable file
41
.rclone_repo/vendor/github.com/pengsrc/go-shared/check/slice.go
generated
vendored
Executable file
@@ -0,0 +1,41 @@
|
||||
package check
|
||||
|
||||
// StringSliceContains iterates over the slice to find the target.
|
||||
func StringSliceContains(slice []string, target string) bool {
|
||||
for _, v := range slice {
|
||||
if v == target {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IntSliceContains iterates over the slice to find the target.
|
||||
func IntSliceContains(slice []int, target int) bool {
|
||||
for _, v := range slice {
|
||||
if v == target {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Int32SliceContains iterates over the slice to find the target.
|
||||
func Int32SliceContains(slice []int32, target int32) bool {
|
||||
for _, v := range slice {
|
||||
if v == target {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Int64SliceContains iterates over the slice to find the target.
|
||||
func Int64SliceContains(slice []int64, target int64) bool {
|
||||
for _, v := range slice {
|
||||
if v == target {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user