dump.go 453 B

12345678910111213141516171819202122232425262728293031323334
  1. package debug
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "os"
  6. "github.com/davecgh/go-spew/spew"
  7. "github.com/sqlc-dev/sqlc/internal/opts"
  8. )
  9. var Active bool
  10. var Debug opts.Debug
  11. func init() {
  12. Active = os.Getenv("SQLCDEBUG") != ""
  13. if Active {
  14. Debug = opts.DebugFromEnv()
  15. }
  16. }
  17. func Dump(n ...interface{}) {
  18. if Active {
  19. spew.Dump(n)
  20. }
  21. }
  22. func DumpAsJSON(a any) {
  23. if Active {
  24. out, _ := json.MarshalIndent(a, "", " ")
  25. fmt.Printf("%s\n", out)
  26. }
  27. }