config.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2013 Dave Collins <dave@davec.name>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. package spew
  17. // ConfigState is used to describe configuration options used by spew to format
  18. // and display values. There is a global instance, Config, that is used to
  19. // control all top-level Formatter and Dump functionality. In addition, each
  20. // SpewState instance provides access to a unique ConfigState which can be used
  21. // to control the configuration of that particular instance.
  22. type ConfigState struct {
  23. // MaxDepth controls the maximum number of levels to descend into nested
  24. // data structures. The default, 0, means there is no limit.
  25. //
  26. // NOTE: Circular data structures are properly detected, so it is not
  27. // necessary to set this value unless you specifically want to limit deeply
  28. // nested data structures.
  29. MaxDepth int
  30. // Indent specifies the string to use for each indentation level. It is
  31. // a single space by default. If you would like more indentation, you might
  32. // set this to a tab with "\t" or perhaps two spaces with " ".
  33. Indent string
  34. // DisableMethods specifies whether or not error and Stringer interfaces are
  35. // invoked for types that implement them.
  36. DisableMethods bool
  37. // DisablePointerMethods specifies whether or not to check for and invoke
  38. // error and Stringer interfaces on types which only accept a pointer
  39. // receiver when the current type is not a pointer.
  40. //
  41. // NOTE: This might be an unsafe action since calling one of these methods
  42. // with a pointer receiver could technically mutate the value, however,
  43. // in practice, types which choose to satisify an error or Stringer
  44. // interface with a pointer receiver should not be mutating their state
  45. // inside these interface methods.
  46. DisablePointerMethods bool
  47. }
  48. // Config is the active configuration of the top-level functions.
  49. // The configuration can be changed by modifying the contents of spew.Config.
  50. var Config ConfigState = ConfigState{Indent: " "}
  51. var defaultConfig = ConfigState{Indent: " "}