github.com/sandwich-go/boost@v1.3.29/xcrypto/algorithm/hide/gen_options_optiongen.go (about) 1 // Code generated by optiongen. DO NOT EDIT. 2 // optiongen: github.com/timestee/optiongen 3 4 package hide 5 6 // Options should use NewOptions to initialize it 7 type Options struct { 8 Suffix string 9 PrefixKeep int 10 SuffixKeep int 11 HideLenMin int 12 HideReplaceWith rune 13 // 0 等长,否则按照指定的长度替换 14 HideReplaceLen int 15 } 16 17 // NewOptions new Options 18 func NewOptions(opts ...Option) *Options { 19 cc := newDefaultOptions() 20 for _, opt := range opts { 21 opt(cc) 22 } 23 if watchDogOptions != nil { 24 watchDogOptions(cc) 25 } 26 return cc 27 } 28 29 // ApplyOption apply multiple new option 30 func (cc *Options) ApplyOption(opts ...Option) { 31 for _, opt := range opts { 32 opt(cc) 33 } 34 } 35 36 // Option option func 37 type Option func(cc *Options) 38 39 // WithSuffix option func for filed Suffix 40 func WithSuffix(v string) Option { 41 return func(cc *Options) { 42 cc.Suffix = v 43 } 44 } 45 46 // WithPrefixKeep option func for filed PrefixKeep 47 func WithPrefixKeep(v int) Option { 48 return func(cc *Options) { 49 cc.PrefixKeep = v 50 } 51 } 52 53 // WithSuffixKeep option func for filed SuffixKeep 54 func WithSuffixKeep(v int) Option { 55 return func(cc *Options) { 56 cc.SuffixKeep = v 57 } 58 } 59 60 // WithHideLenMin option func for filed HideLenMin 61 func WithHideLenMin(v int) Option { 62 return func(cc *Options) { 63 cc.HideLenMin = v 64 } 65 } 66 67 // WithHideReplaceWith option func for filed HideReplaceWith 68 func WithHideReplaceWith(v rune) Option { 69 return func(cc *Options) { 70 cc.HideReplaceWith = v 71 } 72 } 73 74 // WithHideReplaceLen option func for filed HideReplaceLen 75 func WithHideReplaceLen(v int) Option { 76 return func(cc *Options) { 77 cc.HideReplaceLen = v 78 } 79 } 80 81 // InstallOptionsWatchDog the installed func will called when NewOptions called 82 func InstallOptionsWatchDog(dog func(cc *Options)) { watchDogOptions = dog } 83 84 // watchDogOptions global watch dog 85 var watchDogOptions func(cc *Options) 86 87 // newDefaultOptions new default Options 88 func newDefaultOptions() *Options { 89 cc := &Options{} 90 91 for _, opt := range [...]Option{ 92 WithSuffix("hash"), 93 WithPrefixKeep(3), 94 WithSuffixKeep(3), 95 WithHideLenMin(3), 96 WithHideReplaceWith('*'), 97 WithHideReplaceLen(0), 98 } { 99 opt(cc) 100 } 101 102 return cc 103 } 104 105 // all getter func 106 func (cc *Options) GetSuffix() string { return cc.Suffix } 107 func (cc *Options) GetPrefixKeep() int { return cc.PrefixKeep } 108 func (cc *Options) GetSuffixKeep() int { return cc.SuffixKeep } 109 func (cc *Options) GetHideLenMin() int { return cc.HideLenMin } 110 func (cc *Options) GetHideReplaceWith() rune { return cc.HideReplaceWith } 111 func (cc *Options) GetHideReplaceLen() int { return cc.HideReplaceLen } 112 113 // OptionsVisitor visitor interface for Options 114 type OptionsVisitor interface { 115 GetSuffix() string 116 GetPrefixKeep() int 117 GetSuffixKeep() int 118 GetHideLenMin() int 119 GetHideReplaceWith() rune 120 GetHideReplaceLen() int 121 } 122 123 // OptionsInterface visitor + ApplyOption interface for Options 124 type OptionsInterface interface { 125 OptionsVisitor 126 ApplyOption(...Option) 127 }