Documentation ¶
Overview ¶
Copyright © 2020 Marvin
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- func Abs(user, path string) string
- func AnySliceSplit(value interface{}, batchSize int) []interface{}
- func BytesToString(b []byte) string
- func CharsetConvert(data []byte, fromCharset, toCharset string) ([]byte, error)
- func Checksum(file string) (string, error)
- func CompareInter(structA, structB interface{}) ([]interface{}, []interface{})
- func CompareMapInter(mapSA interface{}, mapTB interface{}) (map[string]interface{}, map[string]interface{}, map[string]interface{})
- func Copy(src, dst string) error
- func CreateDir(path string) error
- func CurrentTimeFormatString() string
- func Decrypt(ciphertext string, key []byte) (string, error)
- func Encrypt(text string, key []byte) (string, error)
- func EscapeBinaryCSV(s []byte, escapeBackslash bool, delimiterCsv, separatorCsv string) string
- func ExchangeStringDict(highPriority, lowPriority map[string]string) map[string]string
- func FlattenMap(ms map[string]any) map[string]any
- func FoldMap(ms map[string]any) map[string]any
- func FormatJSONFields(data interface{}) interface{}
- func GetDiskUsage(path string) (*syscall.Statfs_t, error)
- func GetJSONTagFieldValue(obj interface{}) map[string]string
- func GetOutBoundIP() (string, error)
- func GetRandomElem(slice []string) (string, error)
- func GetTopologyUserSudoPrivileges(deployUser string) []string
- func HostWhiteListForInitialCluster(s string) map[string]struct{}
- func IsContainedString(items []string, item string) bool
- func IsContainedStringIgnoreCase(items []string, item string) bool
- func IsDirExist(d string) bool
- func IsPathExist(path string) bool
- func IsPathNotExist(path string) bool
- func IsSubDir(parent, sub string) bool
- func IsValueNil(i interface{}) bool
- func JoinHostPort(host string, port int) string
- func JoinInt(nums []int, delim string) string
- func LogDigitWidth(number int) int
- func MarshalIndentJSON(v any) (string, error)
- func MarshalJSON(v any) (string, error)
- func Max(x, y int64) int64
- func Merge2TomlConfig(comp string, global, overwrite map[string]any) ([]byte, error)
- func MergeConfig(orig map[string]any, overwrites ...map[string]any) map[string]any
- func Min(x, y int64) int64
- func MkdirAll(path string, minPerm os.FileMode) error
- func MultiDirAbs(user, paths string) []string
- func OpenFileInEditor(filename string) error
- func OsArch(os, arch string) string
- func PKCS7Padding(ciphertext []byte, blockSize int) []byte
- func PKCS7UnPadding(origData []byte) ([]byte, error)
- func PackagePath(mirrorDir, comp string, version string, os string, arch string) string
- func PaddingString(padNums int, padStr string, lastPadStr string) string
- func PathNotExistOrCreate(path string) error
- func PrintTable(rows [][]string, header bool)
- func Prompt(prompt string) string
- func PromptForAnswerOrAbortError(answer string, format string, a ...any) error
- func PromptForConfirmAnswer(answer string, format string, a ...any) (bool, string)
- func PromptForConfirmNo(format string, a ...any) (bool, string)
- func PromptForConfirmOrAbortError(format string, a ...any) error
- func PromptForConfirmYes(format string, a ...any) (bool, string)
- func PromptForPassword(format string, a ...any) string
- func RemoveAllDir(dir string) error
- func RemovePrefixOnce(s, prefix string) string
- func RemovePrefixSuffixOnce(str string, prefix, suffix string) string
- func RemoveSuffixOnce(s, suffix string) string
- func ReplaceQuestionPlacholders(qry string, replacePlacs, newPlacs byte) string
- func SaveFileWithBackup(path string, data []byte, backupDir string) error
- func ShowDiff(t1 string, t2 string, w io.Writer)
- func SpecialLettersMySQLCompatibleDatabase(bs []byte) string
- func SpecialLettersOracleCompatibleDatabase(bs []byte) string
- func StrconvFloatBitSize(s string, bitSize int) (float64, error)
- func StrconvIntBitSize(s string, bitSize int) (int64, error)
- func StrconvRune(s string) (int32, error)
- func StrconvUintBitSize(s string, bitSize int) (uint64, error)
- func StringBuilder(str ...string) string
- func StringExtractorWithinBrackets(text string) []string
- func StringExtractorWithinQuotationMarks(text string, patterns ...string) []string
- func StringExtractorWithoutQuotationMarks(text string, patterns ...string) []string
- func StringItemsFilterDifference(originItems, excludeItems []string) []string
- func StringItemsFilterIntersection(originItems, newItems []string) []string
- func StringJoin(strs []string, sep string) string
- func StringLower(str string) string
- func StringLowerSlice(strs []string) []string
- func StringMatcher(str, toMatch string) bool
- func StringPairKey(res map[string]string) string
- func StringReplacer(str, toReplace, replaceWith string) string
- func StringSliceAlignLen(slices [][]string) ([][]string, int)
- func StringSliceRemoveElement(slice []string, elem string) []string
- func StringSliceSplit(items []string, splitCounts int) [][]string
- func StringSplit(str string, sep string) []string
- func StringTrim(originStr string, trimStr string) string
- func StringUpper(str string) string
- func StringUpperSlice(strs []string) []string
- func Ternary(condition bool, a, b any) any
- func TrimIfBothExist(s string, ch rune) string
- func UnmarshalJSON(data []byte, v any) error
- func UnwrapScheme(s string) string
- func UppercaseMap(m interface{}) interface{}
- func ValidateSpecDiff(s1, s2 any) error
- func VersionCompare(curVersion, newVersion string) error
- func VersionOrdinal(version string) string
- func WithHostPort(addr string) string
- func WrapPrefixIPName(localHost string, prefix string, peerAddr string) string
- func WrapScheme(s string, https bool) string
- func WrapSchemes(str string, https bool) []string
- func WrapSchemesForInitialCluster(s string, prefix string, https bool) string
- func WriteFile(name string, data []byte, perm os.FileMode) error
- 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
Constants ¶
const (
ASCIIArtWarning = `` /* 623-byte string literal not displayed */
)
pre-defined ascii art strings
const DefaultEditor = "vi"
DefaultEditor is vi because we're adults ;)
Variables ¶
This section is empty.
Functions ¶
func AnySliceSplit ¶ added in v0.0.9
func AnySliceSplit(value interface{}, batchSize int) []interface{}
AnySliceSplit used for the according to splitCounts, split slice
func BytesToString ¶
BytesToString used for bytes to string, reduce memory https://segmentfault.com/a/1190000037679588
func CharsetConvert ¶
CharsetConvert used for string data charset convert
func CompareInter ¶
func CompareInter(structA, structB interface{}) ([]interface{}, []interface{})
func CompareMapInter ¶
func CompareMapInter(mapSA interface{}, mapTB interface{}) (map[string]interface{}, map[string]interface{}, map[string]interface{})
Key-Value
func CurrentTimeFormatString ¶
func CurrentTimeFormatString() string
CurrentTimeFormatString used for format time string
func EscapeBinaryCSV ¶
EscapeBinaryCSV used for bytes to string
func ExchangeStringDict ¶
ExchangeStringDict used for exchange string dict
func FlattenMap ¶
FlattenMap convert mutil-layer map to single layer
func FormatJSONFields ¶
func FormatJSONFields(data interface{}) interface{}
FormatJSONFields returns format json string
func GetDiskUsage ¶
GetDiskUsage used for get the current dir disk usage size
func GetJSONTagFieldValue ¶
GetJSONTagFieldValue used for get field value with json tag
func GetOutBoundIP ¶ added in v0.0.1
GetOutBoundIP used for the host ipaddr
func GetRandomElem ¶
GetRandomElem used for get random element
func GetTopologyUserSudoPrivileges ¶ added in v0.0.6
func HostWhiteListForInitialCluster ¶
HostWhiteListForInitialCluster remove duplicate addr, returns addr.
func IsContainedString ¶
IsContainedString used for judge items whether is contained the item, and if it's contained, return true
func IsContainedStringIgnoreCase ¶
IsContainedStringIgnoreCase used for judge items whether is contained the item, and if it's contained, return true
func IsDirExist ¶
IsDirExist returns whether the directory is exists.
func IsPathNotExist ¶
IsPathNotExist check whether a path is not exist
func IsValueNil ¶
func IsValueNil(i interface{}) bool
func JoinHostPort ¶
JoinHostPort return host and port
func LogDigitWidth ¶ added in v0.0.9
LogDigitWidth calculates the number of digits of a given positive integer
func MarshalIndentJSON ¶
MarshalIndentJSON returns marshal indent object json
func Merge2TomlConfig ¶
Merge2TomlConfig merge the config of global.
func MergeConfig ¶
MergeConfig merge two or more config into one and unflat them config1:
a.b.a: 1 a.b.b: 2
config2:
a.b.a: 3 a.b.c: 4
config3:
b.c = 5
After MergeConfig(config1, config2, config3):
a: b: a: 3 b: 2 c: 4 b: c: 5
func MultiDirAbs ¶
MultiDirAbs returns the absolute path for multi-dir separated by comma
func OpenFileInEditor ¶
OpenFileInEditor opens filename in a text editor.
func OsArch ¶
OsArch builds an "os/arch" string from input, it converts some similar strings to different words to avoid misreading when displaying in terminal
func PKCS7Padding ¶
func PKCS7UnPadding ¶
func PackagePath ¶
PackagePath return the tar bar path
func PathNotExistOrCreate ¶
PathNotExistOrCreate used for the filepath is whether exist, if not exist, then create
func PrintTable ¶
PrintTable accepts a matrix of strings and print them as ASCII table to terminal
func PromptForAnswerOrAbortError ¶
PromptForAnswerOrAbortError accepts string from console by user, generates AbortError if user does not input the pre-defined answer.
func PromptForConfirmAnswer ¶
PromptForConfirmAnswer accepts string from console by user, default to empty and only return true if the user input is exactly the same as pre-defined answer.
func PromptForConfirmNo ¶
PromptForConfirmNo accepts yes / no from console by user, default to Yes and only return true if the user input is No
func PromptForConfirmOrAbortError ¶
PromptForConfirmOrAbortError accepts yes / no from console by user, generates AbortError if user does not input yes.
func PromptForConfirmYes ¶
PromptForConfirmYes accepts yes / no from console by user, default to No and only return true if the user input is Yes
func PromptForPassword ¶
PromptForPassword reads a password input from console
func RemoveAllDir ¶ added in v0.0.14
RemoveAllDir used to remove dir
func RemovePrefixOnce ¶
func RemovePrefixSuffixOnce ¶
func RemoveSuffixOnce ¶
func ReplaceQuestionPlacholders ¶ added in v0.0.15
ReplaceQuestionPlacholders replaces ? marks with support placeholders.
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 SpecialLettersMySQLCompatibleDatabase ¶
If there are special characters, add \ directly before the special characters. * Determine whether it is a letter: unicode.IsLetter(v) Determine whether it is a decimal number: unicode.IsDigit(v) Determine whether it is a number: unicode.IsNumber(v) Determine whether it is a white space symbol: unicode.IsSpace(v) Determine whether it is a special symbol: unicode.IsSymbol(v) Determine whether it is a Unicode punctuation character: unicode.IsPunct(v) Determine whether it is Chinese: unicode.Han(v)
func StrconvRune ¶
func StringBuilder ¶
StringBuilder used for string builder, and returns string
func StringItemsFilterDifference ¶
StringItemsFilterDifference used for filter difference items, and returns new array string
func StringItemsFilterIntersection ¶
StringItemsFilterIntersection used for filter intersection items in the two items, and return new array string
func StringJoin ¶
StringJoin used for string join, and returns array string
func StringLower ¶
StringLower used for string lower, and returns lower string
func StringLowerSlice ¶
StringLowerSlice used for string slice lower, and returns lower string
func StringMatcher ¶
func StringPairKey ¶
func StringReplacer ¶
func StringSliceAlignLen ¶
func StringSliceRemoveElement ¶ added in v0.0.7
StringSliceRemoveElement used for string slice remove element
func StringSliceSplit ¶ added in v0.0.6
StringSliceSplit used for the according to splitCounts, split slice
func StringSplit ¶
StringSplit used for string split, and returns array string
func StringTrim ¶
func StringUpper ¶
StringUpper used for string upper, and returns upper string
func StringUpperSlice ¶
StringUpperSlice used for string slice upper, and returns upper string
func TrimIfBothExist ¶ added in v0.0.15
TrimIfBothExist Determine whether a specific character exists at the beginning and end of the string, and if so, remove these characters.
func UnmarshalJSON ¶
UnmarshalJSON returns marshal object json
func UnwrapScheme ¶
UnwrapScheme removes http or https scheme from input.
func UppercaseMap ¶ added in v0.0.9
func UppercaseMap(m interface{}) interface{}
UppercaseMap recursively converts all string keys and values within a map to uppercase. It also handles slices of structures by converting their fields to uppercase.
func ValidateSpecDiff ¶
ValidateSpecDiff checks and validates the new spec to see if the modified keys are all marked as editable
func VersionCompare ¶
func VersionOrdinal ¶
VersionOrdinal used for the database version comparison
func WrapPrefixIPName ¶
WrapPrefixIPName returns the name with ip and prefix
func WrapScheme ¶
func WrapSchemes ¶
WrapSchemes adds http or https scheme to input if missing. input could be a comma-separated list.
func WrapSchemesForInitialCluster ¶
WrapSchemesForInitialCluster acts like WrapSchemes, except input is "name=URL,...".
Types ¶
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