github.com/sandwich-go/boost@v1.3.29/xcrypto/algorithm/hide/hashview.go (about) 1 package hide 2 3 import ( 4 "strings" 5 ) 6 7 // Do 隐藏字符串 8 func Do(s string, options ...Option) string { 9 opts := NewOptions(options...) 10 if len(s) <= opts.HideLenMin+opts.PrefixKeep+opts.SuffixKeep { 11 return strings.Repeat("*", len(s)) + "@" + opts.Suffix 12 } 13 replaceLen := opts.HideReplaceLen 14 if replaceLen == 0 { 15 replaceLen = len(s) - opts.PrefixKeep - opts.SuffixKeep 16 } 17 return s[:opts.PrefixKeep] + strings.Repeat(string(opts.HideReplaceWith), replaceLen) + s[len(s)-opts.SuffixKeep:] + "@" + opts.Suffix 18 }