github.com/puellanivis/breton@v0.2.16/lib/files/json/option.go (about) 1 package json 2 3 type config struct { 4 prefix, indent string 5 6 escapeHTML, compact bool 7 } 8 9 // An Option is a function that apply a specific option, then returns an Option function 10 // that will revert the change applied. 11 type Option func(*config) Option 12 13 // WithPrefix returns a function that directs Marshal to use the prefix string given. 14 func WithPrefix(prefix string) Option { 15 return func(c *config) Option { 16 save := c.prefix 17 18 c.prefix = prefix 19 20 return WithPrefix(save) 21 } 22 } 23 24 // WithIndent returns a function that directs Marshal to use the indenting string given. 25 func WithIndent(indent string) Option { 26 return func(c *config) Option { 27 save := c.indent 28 29 c.indent = indent 30 31 return WithIndent(save) 32 } 33 } 34 35 // EscapeHTML returns a function that directs Marshal to either enable or disable HTML escaping. 36 func EscapeHTML(value bool) Option { 37 return func(c *config) Option { 38 save := c.escapeHTML 39 40 c.escapeHTML = value 41 42 return EscapeHTML(save) 43 } 44 } 45 46 // Compact returns a function that directs Marshal to use compact format. 47 func Compact(value bool) Option { 48 return func(c *config) Option { 49 save := c.compact 50 51 c.compact = value 52 53 return Compact(save) 54 } 55 }