github.com/searKing/golang/go@v1.2.117/encoding/prettyjson/encopts_options.go (about) 1 // Code generated by "go-option -type encOpts"; DO NOT EDIT. 2 // Install go-option by "go get install github.com/searKing/golang/tools/go-option" 3 4 package prettyjson 5 6 // A EncOptsOption sets options. 7 type EncOptsOption interface { 8 apply(*encOpts) 9 } 10 11 // EmptyEncOptsOption does not alter the configuration. It can be embedded 12 // in another structure to build custom options. 13 // 14 // This API is EXPERIMENTAL. 15 type EmptyEncOptsOption struct{} 16 17 func (EmptyEncOptsOption) apply(*encOpts) {} 18 19 // EncOptsOptionFunc wraps a function that modifies encOpts into an 20 // implementation of the EncOptsOption interface. 21 type EncOptsOptionFunc func(*encOpts) 22 23 func (f EncOptsOptionFunc) apply(do *encOpts) { 24 f(do) 25 } 26 27 // ApplyOptions call apply() for all options one by one 28 func (o *encOpts) ApplyOptions(options ...EncOptsOption) *encOpts { 29 for _, opt := range options { 30 if opt == nil { 31 continue 32 } 33 opt.apply(o) 34 } 35 return o 36 } 37 38 // withEncOpts sets encOpts. 39 func withEncOpts(v encOpts) EncOptsOption { 40 return EncOptsOptionFunc(func(o *encOpts) { 41 *o = v 42 }) 43 } 44 45 // WithEncOptsQuoted sets quoted in encOpts. 46 // quoted causes primitive fields to be encoded inside JSON strings. 47 func WithEncOptsQuoted(v bool) EncOptsOption { 48 return EncOptsOptionFunc(func(o *encOpts) { 49 o.quoted = v 50 }) 51 } 52 53 // WithEncOptsEscapeHTML sets escapeHTML in encOpts. 54 // escapeHTML causes '<', '>', and '&' to be escaped in JSON strings. 55 func WithEncOptsEscapeHTML(v bool) EncOptsOption { 56 return EncOptsOptionFunc(func(o *encOpts) { 57 o.escapeHTML = v 58 }) 59 } 60 61 // WithEncOptsTruncateBytes sets truncateBytes in encOpts. 62 func WithEncOptsTruncateBytes(v int) EncOptsOption { 63 return EncOptsOptionFunc(func(o *encOpts) { 64 o.truncateBytes = v 65 }) 66 } 67 68 // WithEncOptsTruncateString sets truncateString in encOpts. 69 func WithEncOptsTruncateString(v int) EncOptsOption { 70 return EncOptsOptionFunc(func(o *encOpts) { 71 o.truncateString = v 72 }) 73 } 74 75 // WithEncOptsTruncateMap sets truncateMap in encOpts. 76 func WithEncOptsTruncateMap(v int) EncOptsOption { 77 return EncOptsOptionFunc(func(o *encOpts) { 78 o.truncateMap = v 79 }) 80 } 81 82 // WithEncOptsTruncateSliceOrArray sets truncateSliceOrArray in encOpts. 83 func WithEncOptsTruncateSliceOrArray(v int) EncOptsOption { 84 return EncOptsOptionFunc(func(o *encOpts) { 85 o.truncateSliceOrArray = v 86 }) 87 } 88 89 // WithEncOptsTruncateUrl sets truncateUrl in encOpts. 90 // truncate query and fragment in url 91 func WithEncOptsTruncateUrl(v bool) EncOptsOption { 92 return EncOptsOptionFunc(func(o *encOpts) { 93 o.truncateUrl = v 94 }) 95 } 96 97 // WithEncOptsOmitEmpty sets omitEmpty in encOpts. 98 func WithEncOptsOmitEmpty(v bool) EncOptsOption { 99 return EncOptsOptionFunc(func(o *encOpts) { 100 o.omitEmpty = v 101 }) 102 }