github.com/searKing/golang/go@v1.2.74/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 // WithEncOptsQuoted sets quoted in encOpts. 39 // quoted causes primitive fields to be encoded inside JSON strings. 40 func WithEncOptsQuoted(v bool) EncOptsOption { 41 return EncOptsOptionFunc(func(o *encOpts) { 42 o.quoted = v 43 }) 44 } 45 46 // WithEncOptsEscapeHTML sets escapeHTML in encOpts. 47 // escapeHTML causes '<', '>', and '&' to be escaped in JSON strings. 48 func WithEncOptsEscapeHTML(v bool) EncOptsOption { 49 return EncOptsOptionFunc(func(o *encOpts) { 50 o.escapeHTML = v 51 }) 52 } 53 54 // WithEncOptsTruncateBytes sets truncateBytes in encOpts. 55 func WithEncOptsTruncateBytes(v int) EncOptsOption { 56 return EncOptsOptionFunc(func(o *encOpts) { 57 o.truncateBytes = v 58 }) 59 } 60 61 // WithEncOptsTruncateString sets truncateString in encOpts. 62 func WithEncOptsTruncateString(v int) EncOptsOption { 63 return EncOptsOptionFunc(func(o *encOpts) { 64 o.truncateString = v 65 }) 66 } 67 68 // WithEncOptsTruncateMap sets truncateMap in encOpts. 69 func WithEncOptsTruncateMap(v int) EncOptsOption { 70 return EncOptsOptionFunc(func(o *encOpts) { 71 o.truncateMap = v 72 }) 73 } 74 75 // WithEncOptsTruncateSlice sets truncateSlice in encOpts. 76 func WithEncOptsTruncateSlice(v int) EncOptsOption { 77 return EncOptsOptionFunc(func(o *encOpts) { 78 o.truncateSlice = v 79 }) 80 } 81 82 // WithEncOptsTruncateArray sets truncateArray in encOpts. 83 func WithEncOptsTruncateArray(v int) EncOptsOption { 84 return EncOptsOptionFunc(func(o *encOpts) { 85 o.truncateArray = v 86 }) 87 }