config.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 currently only a single global instance, Config,
  19. // that is used to control all Formatter and Dump functionality. This state
  20. // is designed so that it would be fairly simple to add the ability to have
  21. // unique config per Formatter or dumpState instance if there is demand for
  22. // such a feature.
  23. type ConfigState struct {
  24. // MaxDepth controls the maximum number of levels to descend into nested
  25. // data structures. The default, 0, means there is no limit.
  26. //
  27. // NOTE: Circular data structures are properly detected, so it is not
  28. // necessary to set this value unless you specifically want to limit deeply
  29. // nested data structures.
  30. MaxDepth int
  31. // Indent specifies the string to use for each indentation level. It is
  32. // a single space by default. If you would like more indentation, you might
  33. // set this to a tab with "\t" or perhaps two spaces with " ".
  34. Indent string
  35. // DisableMethods specifies whether or not error and Stringer interfaces are
  36. // invoked for types that implement them.
  37. DisableMethods bool
  38. // DisablePointerMethods specifies whether or not to check for and invoke
  39. // error and Stringer interfaces on types which only accept a pointer
  40. // receiver when the current type is not a pointer.
  41. //
  42. // NOTE: This might be an unsafe action since calling one of these methods
  43. // with a pointer receiver could technically mutate the value, however,
  44. // in practice, types which choose to satisify an error or Stringer
  45. // interface with a pointer receiver should not be mutating their state
  46. // inside these interface methods.
  47. DisablePointerMethods bool
  48. }
  49. // Config is the active configuration in use by spew. The configuration
  50. // can be changed by modifying the contents of spew.Config.
  51. var Config ConfigState = ConfigState{Indent: " "}
  52. var defaultConfig = ConfigState{Indent: " "}