Documentation ¶
Index ¶
- Constants
- Variables
- func Abbreviate(s string, maxLen int, ellipse string) string
- func AbbreviateAny(s any, maxLen int, ellipse string) any
- func AbbreviateBytes(p []byte, maxLen int, ellipse string) []byte
- func Alphanumeric(u uint8) bool
- func AnyOf[T comparable](target T, anys ...T) bool
- func AnyOfFunc[T any](target T, f func(idx int, elem, target T) bool, anys ...T) bool
- func Base64() *b64
- func Bytes(s uint64) string
- func Close[T io.Closer](closers ...T) error
- func CommonDir(dirs []string) string
- func Contains(s string, subs ...string) bool
- func ContainsFold(s string, subs ...string) bool
- func CopyShuffle[T any](a []T) []T
- func DecodeBase64(dst io.Writer, src io.Reader) (int64, error)
- func EncodeBase64(dst io.Writer, src io.Reader, flags ...Base64Flags) (int64, error)
- func Eval(s string, varValue VarValue) string
- func Exists(name string) (bool, error)
- func Exit(msg string, code int)
- func ExitIfErr(err error)
- func ExpandAtFile(s string) (string, error)
- func ExpandFilename(file string) (string, error)
- func ExpandHome(s string) string
- func ExpandRange(f string) []string
- func Fields(s string, count int) []string
- func FieldsFunc(s string, count int, f func(rune) bool) []string
- func FieldsFuncX(s, keepStart, keepEnd string, count int, f func(rune) bool) []string
- func FieldsX(s, keepStart, keepEnd string, count int) []string
- func FindFlag(args []string, targetNames ...string) (value string, found bool)
- func FnMatch(pattern, name string, caseInsensitive bool) (matched bool, err error)
- func GetFuncName(i interface{}) string
- func GetPbePwd() string
- func Getenv[T Parseable](name string, defaultValue T) (T, error)
- func GetenvBool(envName string, defaultValue bool) (bool, error)
- func GetenvBytes(name string, defaultValue uint64) (uint64, error)
- func Gzip(data []byte) ([]byte, error)
- func HasPrefix(s string, prefix ...string) bool
- func HasSuffix(s string, suffix ...string) bool
- func IBytes(s uint64) string
- func If[T any](condition bool, a, b T) T
- func IfFunc[T any](condition bool, a, b func() T) T
- func IndexN(s, sep string, n int) int
- func IndexOf[T comparable](target T, anys ...T) int
- func IndexOfFunc[T any](target T, f func(idx int, elem, target T) bool, anys ...T) int
- func Is029(v int32) bool
- func IsA2Z(v int32) bool
- func IsDigits(s string) bool
- func Isa2z(v int32) bool
- func JSONPretty(data any) string
- func Json(v any) []byte
- func Lines(filePath string) (lines []string, err error)
- func LinesChan(filePath string, chSize int) (ch chan string, err error)
- func MapGet[K comparable, V any](m map[K]V, k K, defaultVal V) V
- func MapGetF[K comparable, V any](m map[K]V, k K, defaultF func() V) V
- func MapJoin[K comparable, V any](m map[K]V, kkSep, kvSep string) string
- func MapKeys[K comparable, V any](m map[K]V) []K
- func MapKeysSorted[K constraints.Ordered, V any](m map[K]V) []K
- func MapValues[K comparable, V any](m map[K]V) []V
- func MapWalk[K comparable, V any](m map[K]V, walker func(k K, v V) bool)
- func Must[A any](a A, err error) A
- func OpenInBrowser(addr string, paths ...string) (string, error)
- func Or[T comparable](a, b T) T
- func PanicErr(err error)
- func Parse[T Parseable](str string) (T, error)
- func ParseArgs(a interface{}, args []string, optionFns ...FlagParseOptionsFn)
- func ParseBool(s string) (bool, error)
- func ParseBytes(s string) (uint64, error)
- func ParseDuration(s string) time.Duration
- func ParseFlag(a interface{}, optionFns ...FlagParseOptionsFn)
- func PbeDecode(p string) (string, error)
- func PbeDecrypt(cipherText, password string, iterations int) (string, error)
- func PbeDecryptFile(filename, passStr string)
- func PbeDecryptSalt(cipherText, password, fixedSalt string, iterations int) (string, error)
- func PbeEncode(p string) (string, error)
- func PbeEncrypt(plainText, password string, iterations int) (string, error)
- func PbeEncryptFile(filename, passStr string)
- func PbeEncryptFileUpdate(filename, passStr, pbenew string)
- func PbeEncryptSalt(plainText, password, fixedSalt string, iterations int) (string, error)
- func PbePrintDecrypt(passStr string, cipherText ...string)
- func PbePrintEncrypt(passStr string, plains ...string)
- func Pick1[T any](a T, _ error) T
- func Ptr[T any](val T) *T
- func QuoteSingle(s string) string
- func Rand() random
- func ReadAll(r io.Reader) (string, error)
- func ReadFile(filename string) ([]byte, error)
- func Repeat(s, separator string, count int) string
- func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error)
- func Split(s, sep string) []string
- func Split2(s, sep string) (s1, s2 string)
- func SplitFunc(idx int, sub, subSep string, cur []string) (splitSub string, ok, kontinue bool)
- func SplitN(s, sep string, n int, ...) []string
- func SplitReg(s string, re *regexp.Regexp, n int) []string
- func SplitSeps(s string, seps string, n int) []string
- func SplitToMap(s string, kkSep, kvSep string) map[string]string
- func SplitX(s string, separate string, ocs ...OpenClose) []string
- func ToCamel(s string) string
- func ToCamelLower(s string) string
- func ToDelimited(s string, del uint8) string
- func ToDelimitedScreaming(s string, del uint8, screaming bool) string
- func ToDelimitedUpper(s string, del uint8) string
- func ToKebab(s string) string
- func ToKebabUpper(s string) string
- func ToSet[K comparable](v []K) map[K]bool
- func ToSnake(s string) string
- func ToSnakeUpper(s string) string
- func Ungzip(data []byte) ([]byte, error)
- func UnquoteSingle(s string) (string, error)
- func WriteTempFile(tempDir, pattern string, data []byte, errorPanic bool) (name string, err error)
- type Base64Flags
- type CamelCaseEntries
- type CamelCaseEntry
- type CamelCaseEntryClass
- type CardBin
- type DurFraction
- type Expand
- type ExpandPart
- type Expandable
- type FlagParseOptions
- type FlagParseOptionsFn
- type FlagPostProcessor
- type FlagSize
- type FlagStringBool
- type FlagUsageShower
- type FlagVersionShower
- type GenFn
- type GenFnFn
- type Literal
- type MapGenValue
- type OpenClose
- type Pair
- type Parseable
- type Part
- type Parts
- type Pbe
- type Prof
- type RandImgConfig
- type RandomImageResult
- type StructTag
- type StructTags
- func (t *StructTags) AddOptions(key string, options ...string) error
- func (t *StructTags) Delete(keys ...string)
- func (t *StructTags) DeleteOptions(key string, options ...string) error
- func (t *StructTags) Get(key string) (*StructTag, error)
- func (t *StructTags) GetTag(key string) string
- func (t *StructTags) Keys() []string
- func (t *StructTags) Len() int
- func (t *StructTags) Less(i int, j int) bool
- func (t *StructTags) Set(tag *StructTag) error
- func (t *StructTags) String() string
- func (t *StructTags) Swap(i int, j int)
- func (t *StructTags) Tags() []*StructTag
- type Sub
- type SubTxt
- type SubVar
- type Subs
- type Valuer
- type ValuerHandler
- type Var
- type VarValue
- type VarValueHandler
Examples ¶
Constants ¶
const ( Byte = 1 << (iota * 10) KiByte MiByte GiByte TiByte PiByte EiByte )
IEC Sizes. kibis of bits
const ( IByte = 1 KByte = IByte * 1000 MByte = KByte * 1000 GByte = MByte * 1000 TByte = GByte * 1000 PByte = TByte * 1000 EByte = PByte * 1000 )
SI Sizes.
const DefaultEllipse = "…"
DefaultEllipse is the default char for marking abbreviation
const PbePwd = "pbepwd"
PbePwd defines the keyword for client flag.
const Separator = os.PathSeparator
Variables ¶
var ( ErrTagSyntax = errors.New("bad syntax for struct tag pair") ErrTagKeySyntax = errors.New("bad syntax for struct tag key") ErrTagValueSyntax = errors.New("bad syntax for struct tag value") ErrKeyNotExist = errors.New("tag key does not exist") ErrTagNotExist = errors.New("tag does not exist") )
var AreaCode = [...]string{
"11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "35", "36", "37", "41", "42", "43", "44",
"45", "46", "50", "51", "52", "53", "54", "61", "62", "63", "64", "65", "71", "81", "82", "91",
}
var AreaCodeMap = map[string]string{
"11": "北京", "12": "天津", "13": "河北", "14": "山西", "15": "内蒙古", "21": "辽宁", "22": "吉林", "23": "黑龙江",
"31": "上海", "32": "江苏", "33": "浙江", "34": "安徽", "35": "福建", "36": "江西", "37": "山东", "41": "河南", "42": "湖北",
"43": "湖南", "44": "广东", "45": "广西", "46": "海南", "50": "重庆", "51": "四川", "52": "贵州", "53": "云南", "54": "西藏",
"61": "陕西", "62": "甘肃", "63": "青海", "64": "宁夏", "65": "新疆", "71": "台湾", "81": "香港", "82": "澳门", "91": "国外",
}
var ErrBadPattern = errors.New("syntax error in pattern")
ErrBadPattern indicates a pattern was malformed.
var ErrSyntax = errors.New("invalid syntax")
var Surnames = []string{}/* 292 elements not displayed */
var ValCodeArr = [...]string{
"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2",
}
var Wi = [...]int{
7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2,
}
Functions ¶
func Abbreviate ¶
Abbreviate 将 string/[]byte 缩略到 maxLen (不包含 ellipse)
func AnyOf ¶
func AnyOf[T comparable](target T, anys ...T) bool
func Bytes ¶
Bytes produces a human readable representation of an SI size.
See also: ParseBytes.
Bytes(82854982) -> 83 MB
func ContainsFold ¶
func CopyShuffle ¶
func CopyShuffle[T any](a []T) []T
func DecodeBase64 ¶
Decode copies io.Reader which is in base64 format ( any one of StdEncoding/URLEncoding/RawStdEncoding/RawURLEncoding).
func EncodeBase64 ¶
EncodeBase64 copies io.Reader to io.Writer which is in base64 format ( any one of StdEncoding/URLEncoding/RawStdEncoding/RawURLEncoding).
func ExpandAtFile ¶
ExpandAtFile returns argument s if it starts with @filename, the file contents will be replaced as the data.
func ExpandFilename ¶
ExpandFilename first expand ~, then expand symbol link
func ExpandHome ¶
func ExpandRange ¶
ExpandRange expands a string like 1-3 to [1,2,3]
func Fields ¶
Fields splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an empty slice if s contains only white space. The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder. n == 0: the result is nil (zero substrings) n < 0: all substrings
Code are copy from strings.Fields and add count parameter to control the max fields.
func FieldsFunc ¶
FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) and returns an array of slices of s. If all code points in s satisfy f(c) or the string is empty, an empty slice is returned. FieldsFunc makes no guarantees about the order in which it calls f(c). If f does not return consistent results for a given c, FieldsFunc may crash.
func FieldsFuncX ¶
FieldsFuncX splits the string s at each run of Unicode code points c satisfying f(c) and returns an array of slices of s. If all code points in s satisfy f(c) or the string is empty, an empty slice is returned. FieldsFunc makes no guarantees about the order in which it calls f(c). If f does not return consistent results for a given c, FieldsFunc may crash.
func FieldsX ¶
FieldsX splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an empty slice if s contains only white space. The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder. n == 0: the result is nil (zero substrings) n < 0: all substrings
Code are copy from strings.Fields and add count parameter to control the max fields.
func FnMatch ¶
FnMatch reports whether name matches the shell file name pattern in case insensitive for non-pattern parts. The pattern syntax is:
pattern: { term } term: '*' matches any sequence of non-Separator characters '?' matches any single non-Separator character '[' [ '^' ] { character-range } ']' character class (must be non-empty) c matches character c (c != '*', '?', '\\', '[') '\\' c matches character c character-range: c matches character c (c != '\\', '-', ']') '\\' c matches character c lo '-' hi matches character c for lo <= c <= hi
Match requires pattern to match all of name, not just a substring. The only possible returned error is ErrBadPattern, when pattern is malformed.
On Windows, escaping is disabled. Instead, '\\' is treated as path separator.
func GetFuncName ¶
func GetFuncName(i interface{}) string
GetFuncName returns the func name of a func.
func GetenvBytes ¶
GetenvBytes 获得环境变量 name 的值所表示的大小,例如. 30MiB
func IBytes ¶
IBytes produces a human readable representation of an IEC size.
See also: ParseBytes.
IBytes(82854982) -> 79 MiB
func If ¶
Example ¶
package main import ( "fmt" "github.com/bingoohuang/ngg/ss" ) func main() { fmt.Println(ss.If(true, "bingoo", "huang")) fmt.Println(ss.If(false, "bingoo", "huang")) }
Output: bingoo huang
func IndexN ¶
IndexN 返回字符串 s 中第 n 个子字符串 sub 的索引。 如果 n 是正数,则从左到右查找第 n 个 sub 的位置。 如果 n 是负数,则从右到左查找第 -n 个 sub 的位置。 如果找不到,返回 -1
func IndexOf ¶
func IndexOf[T comparable](target T, anys ...T) int
func IndexOfFunc ¶
func MapGet ¶
func MapGet[K comparable, V any](m map[K]V, k K, defaultVal V) V
func MapGetF ¶
func MapGetF[K comparable, V any](m map[K]V, k K, defaultF func() V) V
func MapKeys ¶
func MapKeys[K comparable, V any](m map[K]V) []K
func MapKeysSorted ¶
func MapKeysSorted[K constraints.Ordered, V any](m map[K]V) []K
func MapValues ¶
func MapValues[K comparable, V any](m map[K]V) []V
func MapWalk ¶
func MapWalk[K comparable, V any](m map[K]V, walker func(k K, v V) bool)
func Or ¶
func Or[T comparable](a, b T) T
func ParseArgs ¶
func ParseArgs(a interface{}, args []string, optionFns ...FlagParseOptionsFn)
func ParseBool ¶
ParseBool returns the boolean value represented by the string. It accepts 1, t, true, y, yes, on as true with camel case incentive and accepts 0, f false, n, no, off as false with camel case incentive Any other value returns an error.
func ParseBytes ¶
ParseBytes parses a string representation of bytes into the number of bytes it represents.
See Also: Bytes, IBytes.
ParseBytes("42 MB") -> 42000000, nil ParseBytes("42 mib") -> 44040192, nil
func ParseDuration ¶
func ParseFlag ¶
func ParseFlag(a interface{}, optionFns ...FlagParseOptionsFn)
func PbeDecrypt ¶
PbeDecrypt PrintDecrypt the cipherText(result of Encrypt) based on password and iterations.
func PbeDecryptFile ¶
func PbeDecryptFile(filename, passStr string)
func PbeDecryptSalt ¶
PbeDecryptSalt PrintDecrypt the cipherText(result of EncryptSalt) based on password and iterations.
func PbeEncode ¶
PbeEncode encrypts p by PBEWithMD5AndDES with 19 iterations. it will prompt password if viper get none.
func PbeEncrypt ¶
PbeEncrypt PrintEncrypt the plainText based on password and iterations with random salt. The result contains the first 8 bytes salt before BASE64.
func PbeEncryptFile ¶
func PbeEncryptFile(filename, passStr string)
func PbeEncryptFileUpdate ¶
func PbeEncryptFileUpdate(filename, passStr, pbenew string)
func PbeEncryptSalt ¶
PbeEncryptSalt PrintEncrypt the plainText based on password and iterations with fixed salt.
func PbePrintDecrypt ¶
PbePrintDecrypt prints the PBE decryption.
func PbePrintEncrypt ¶
PbePrintEncrypt prints the PBE encryption.
func QuoteSingle ¶
QuoteSingle returns a single-quoted Go string literal representing s. But, nothing else escapes.
Example ¶
package main import ( "fmt" "github.com/bingoohuang/ngg/ss" ) func main() { s := ss.QuoteSingle(`"Fran & Freddie's Diner ☺"`) fmt.Println(s) s = ss.QuoteSingle(`rock'n'roll`) fmt.Println(s) }
Output: '"Fran & Freddie\'s Diner ☺"' 'rock\'n\'roll'
func Repeat ¶
Repeat returns a new string consisting of count copies of the string s with separator.
It panics if count is negative or if the result of (len(s) * count) overflows.
func ScanLines ¶
ScanLines is a split function for a Scanner that returns each line of text, with end-of-line marker. The returned line may be empty. The end-of-line marker is one optional carriage return followed by one mandatory newline. In regular expression notation, it is `\r?\n`. The last non-empty line of input will be returned even if it has no newline.
func Split ¶
Example ¶
for _, c := range []string{ "", "lowercase", "Class", "MyClass", "MyC", "HTML", "PDFLoader", "AString", "SimpleXMLParser", "vimRPCPlugin", "GL11Version", "99Bottles", "May5", "BFG9000", "BöseÜberraschung", "Two spaces", "BadUTF8\xe2\xe2\xa1", } { fmt.Printf("%#v => %#v\n", c, SplitCamelcase(c).Entries()) }
Output: "" => []string{} "lowercase" => []string{"lowercase"} "Class" => []string{"Class"} "MyClass" => []string{"My", "Class"} "MyC" => []string{"My", "C"} "HTML" => []string{"HTML"} "PDFLoader" => []string{"PDF", "Loader"} "AString" => []string{"A", "String"} "SimpleXMLParser" => []string{"Simple", "XML", "Parser"} "vimRPCPlugin" => []string{"vim", "RPC", "Plugin"} "GL11Version" => []string{"GL", "11", "Version"} "99Bottles" => []string{"99", "Bottles"} "May5" => []string{"May", "5"} "BFG9000" => []string{"BFG", "9000"} "BöseÜberraschung" => []string{"Böse", "Überraschung"} "Two spaces" => []string{"Two", " ", "spaces"} "BadUTF8\xe2\xe2\xa1" => []string{"BadUTF8\xe2\xe2\xa1"}
func SplitReg ¶
SplitReg slices s into substrings separated by the expression and returns a slice of the substrings between those expression matches. (especially including the tail separator.)
The slice returned by this method consists of all the substrings of s not contained in the slice returned by FindAllString. When called on an expression that contains no metacharacters, it is equivalent to strings.SplitN.
Example:
s := regexp.MustCompile("a*").SplitReg("abaabaccadaaae", 5) // s: ["", "b", "b", "c", "cadaaae"]
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder. n == 0: the result is nil (zero substrings) n < 0: all substrings
func SplitToMap ¶
SplitToMap 将字符串 s 分割成 map, 其中 key 和 value 之间的间隔符是 kvSep, kv 和 kv 之间的分隔符是 kkSep
func ToCamelLower ¶
ToCamelLower converts a string to lowerCamelCase
func ToDelimited ¶
ToDelimited converts a string to delimited.snake.case (in this case `del = '.'`)
func ToDelimitedScreaming ¶
ToDelimitedScreaming converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `del = '.'; screaming = true`) or delimited.snake.case (in this case `del = '.'; screaming = false`)
func ToDelimitedUpper ¶
ToDelimitedUpper converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `del = '.'; screaming = true`) or delimited.snake.case (in this case `del = '.'; screaming = false`)
func ToKebabUpper ¶
ToKebabUpper converts a string to SCREAMING-KEBAB-CASE
func ToSet ¶
func ToSet[K comparable](v []K) map[K]bool
func ToSnakeUpper ¶
ToSnakeUpper converts a string to SCREAMING_SNAKE_CASE
func UnquoteSingle ¶
UnquoteSingle interprets s as a single-quoted Go string literal, returning the string value that s quotes.
Example ¶
package main import ( "fmt" "github.com/bingoohuang/ngg/ss" ) func main() { s, err := ss.UnquoteSingle("You can't unquote a string without quotes") fmt.Printf("%q, %v\n", s, err) s, err = ss.UnquoteSingle("\"The string must be either double-quoted\"") fmt.Printf("%q, %v\n", s, err) s, err = ss.UnquoteSingle("`or backquoted.`") fmt.Printf("%q, %v\n", s, err) s, err = ss.UnquoteSingle("'\u263a'") fmt.Printf("%q, %v\n", s, err) s, err = ss.UnquoteSingle("'\u2639\u2639'") fmt.Printf("%q, %v\n", s, err) s, err = ss.UnquoteSingle("'\\'The string must be either single-quoted\\''") fmt.Printf("%q, %v\n", s, err) }
Output: "", invalid syntax "", invalid syntax "", invalid syntax "☺", <nil> "☹☹", <nil> "'The string must be either single-quoted'", <nil>
Types ¶
type CamelCaseEntries ¶
type CamelCaseEntries []CamelCaseEntry
func SplitCamelcase ¶
func SplitCamelcase(src string) (entries CamelCaseEntries)
SplitCamelcase splits the camelcase word and returns a list of words. It also supports digits. Both lower camel case and upper camel case are supported. For more info please check: http://en.wikipedia.org/wiki/CamelCase https://github.com/proproto/camelcase/blob/master/camelcase.go
Examples
"" => [""] "lowercase" => ["lowercase"] "Class" => ["Class"] "MyClass" => ["My", "Class"] "MyC" => ["My", "C"] "HTML" => ["HTML"] "PDFLoader" => ["PDF", "Loader"] "AString" => ["A", "String"] "SimpleXMLParser" => ["Simple", "XML", "Parser"] "vimRPCPlugin" => ["vim", "RPC", "Plugin"] "GL11Version" => ["GL", "11", "Version"] "99Bottles" => ["99", "Bottles"] "May5" => ["May", "5"] "BFG9000" => ["BFG", "9000"] "BöseÜberraschung" => ["Böse", "Überraschung"] "Two spaces" => ["Two", " ", "spaces"] "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"]
Splitting rules
- If string is not valid UTF-8, return it without splitting as single item array.
- Assign all unicode characters into one of 4 sets: lower case letters, upper case letters, numbers, and all other characters.
- Iterate through characters of string, introducing splits between adjacent characters that belong to different sets.
- Iterate through array of split strings, and if a given string is upper case: if subsequent string is lower case: move last character of upper case string to beginning of lower case string
func (CamelCaseEntries) Entries ¶
func (c CamelCaseEntries) Entries() []string
type CamelCaseEntry ¶
type CamelCaseEntry struct { Class CamelCaseEntryClass Entry string }
func (CamelCaseEntry) String ¶
func (c CamelCaseEntry) String() string
type CamelCaseEntryClass ¶
type CamelCaseEntryClass int
const ( CamelCaseEntryLower CamelCaseEntryClass CamelCaseEntryUpper CamelCaseEntryDigit CamelCaseEntryOther )
type DurFraction ¶
func ParseDur ¶
ParseDur parses a duration string(add d and w to standard time.Parse). A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d", "w". allowUnits 允许的单位, 不传,使用上面的 unitMap 中的默认单位
type Expand ¶
type Expand struct {
// contains filtered or unexported fields
}
Expand structured a expandable unit.
func (Expand) MakeExpand ¶
MakeExpand makes a expanded string slice of expand.
type ExpandPart ¶
type ExpandPart struct {
// contains filtered or unexported fields
}
ExpandPart as a part of something.
func MakeExpandPart ¶
func MakeExpandPart(s string) ExpandPart
MakeExpandPart makes an expanded part.
func (ExpandPart) ExpandPart ¶
func (f ExpandPart) ExpandPart(i int) string
ExpandPart returns i'th item.
type Expandable ¶
type Expandable interface { // MakePart returns i'th item. ExpandPart(i int) string // Len returns the length of part items. Len() int }
Expandable abstract a thing that can be expanded to parts.
type FlagParseOptions ¶
type FlagParseOptions struct {
// contains filtered or unexported fields
}
type FlagParseOptionsFn ¶
type FlagParseOptionsFn func(*FlagParseOptions)
func AutoLoadYaml ¶
func AutoLoadYaml(flagName, defaultCnf string) FlagParseOptionsFn
type FlagPostProcessor ¶
type FlagPostProcessor interface {
PostProcess()
}
type FlagStringBool ¶
func (*FlagStringBool) Get ¶
func (i *FlagStringBool) Get() interface{}
func (*FlagStringBool) Set ¶
func (i *FlagStringBool) Set(value string) error
func (*FlagStringBool) SetExists ¶
func (i *FlagStringBool) SetExists(b bool)
func (*FlagStringBool) String ¶
func (i *FlagStringBool) String() string
func (*FlagStringBool) Type ¶
func (i *FlagStringBool) Type() string
type FlagUsageShower ¶
type FlagUsageShower interface {
Usage() string
}
type FlagVersionShower ¶
type FlagVersionShower interface {
VersionInfo() string
}
type MapGenValue ¶
type MapGenValue struct { Map map[string]GenFn sync.RWMutex GenMap map[string]GenFnFn MissedVars map[string]bool Vars map[string]any }
func NewMapGenValue ¶
func NewMapGenValue(m map[string]GenFnFn) *MapGenValue
func (*MapGenValue) GetValue ¶
func (m *MapGenValue) GetValue(name, params, expr string) any
func (*MapGenValue) Value ¶
func (m *MapGenValue) Value(name, params, expr string) any
type Pbe ¶
type Pbe struct {
Passphrase string
}
Pbe configs the passphrase.
func (Pbe) Encode ¶
Encode will PBE encrypt the passwords in the text passwords should be as any of following format and its converted pattern 1. {PWD:clear} -> {PBE:cyphered} 2. [PWD:clear] -> {PBE:cyphered} 3. (PWD:clear) -> {PBE:cyphered} 4. "PWD:clear" -> "{PBE:cyphered}" 5. PWD:clear -> {PBE:cyphered}
type RandImgConfig ¶
func (*RandImgConfig) Gen ¶
func (c *RandImgConfig) Gen(imageFormat string) ([]byte, int)
Gen generate a random image with imageFormat (jpg/png) . refer: https://onlinejpgtools.com/generate-random-jpg
type RandomImageResult ¶
type StructTag ¶
type StructTag struct { // Key is the tag key, such as json, xml, etc.. // i.e: `json:"foo,omitempty". Here key is: "json" Key string // Name is a part of the value // i.e: `json:"foo,omitempty". Here name is: "foo" Name string // Options is a part of the value. It contains a slice of tag options i.e: // `json:"foo,omitempty". Here options is: ["omitempty"] Options []string // OptionsMap is a map of the options // i.e: `json:"foo,omitempty". Here OptionsMap is: {"foo":"", "omitempty": ""} OptionsMap map[string]string // Raw is the raw value of the tag // i.e: `json:"foo,omitempty". Here Raw is: "foo,omitempty" Raw string }
StructTag defines a single struct's string literal tag
func ParseStructTag ¶
type StructTags ¶
type StructTags struct {
// contains filtered or unexported fields
}
StructTags represent a set of tags from a single struct field
func ParseStructTags ¶
func ParseStructTags(tag string) (*StructTags, error)
Parse parses a single struct field tag and returns the set of tags.
func (*StructTags) AddOptions ¶
func (t *StructTags) AddOptions(key string, options ...string) error
AddOptions adds the given option for the given key. If the option already exists it doesn't add it again.
func (*StructTags) Delete ¶
func (t *StructTags) Delete(keys ...string)
Delete deletes the tag for the given keys
func (*StructTags) DeleteOptions ¶
func (t *StructTags) DeleteOptions(key string, options ...string) error
DeleteOptions deletes the given options for the given key
func (*StructTags) Get ¶
func (t *StructTags) Get(key string) (*StructTag, error)
Get returns the tag associated with the given key. If the key is present in the tag the value (which may be empty) is returned. Otherwise, the returned value will be the empty string. The ok return value reports whether the tag exists or not (which the return value is nil).
func (*StructTags) GetTag ¶
func (t *StructTags) GetTag(key string) string
func (*StructTags) Len ¶
func (t *StructTags) Len() int
func (*StructTags) Set ¶
func (t *StructTags) Set(tag *StructTag) error
Set sets the given tag. If the tag key already exists it'll override it
func (*StructTags) String ¶
func (t *StructTags) String() string
String reassembles the tags into a valid literal tag field representation
func (*StructTags) Swap ¶
func (t *StructTags) Swap(i int, j int)
func (*StructTags) Tags ¶
func (t *StructTags) Tags() []*StructTag
Tags returns a slice of tags. The order is the original tag order unless it was changed.
type ValuerHandler ¶
type VarValueHandler ¶
func (VarValueHandler) GetValue ¶
func (v VarValueHandler) GetValue(name, params, expr string) any