Giter Club home page Giter Club logo

dumper's Introduction

Go Dumper

When debugging Go code, being able to dump values with nice formatting and colors can go a long way:

package main

import (
    "time"

    . "github.com/symfony-cli/dumper"
)

func main() {
    now := time.Now().Local()
    Dump(now)
}

Output:

time.Time{{
  wall: 507838786, // uint64
  ext: 63649250679, // int64
  loc: &time.Location { // (0x0014c3a0)
    name: "",
    zone: nil, // []time.zone
    tx: nil, // []time.zoneTrans
    cacheStart: 0, // int64,
    cacheEnd: 0, // int64,
    cacheZone: nil, // &time.zone
  },
}

Custom Dumpers

Implement the Dumpable interface on your types to take control of how your type is dumped:

type Dumpable interface {
    Dump(State)
}

Use the available helpers on the State object to write your custom dump. Alternatively, you can write directly to the provided stream. In both cases, your type name (and eventually the pointer comment) will be automatically added.

Read he test suite for some examples.

Another alternative, useful for package you don't maintain is to register a function of type DumpFunc:

func init() {
    RegisterCustomDumper(http.Request{}, dumpHttpRequest)
}

func dumpHttpRequest(s State, v reflect.Value) {
    for _, f := range []string{"Status", "Proto"} {
        s.DumpStructField(f, v.FieldByName(f))
    }
    s.AddComment("Hello World!")
}

dumper's People

Contributors

fabpot avatar stefanosps avatar tucksaun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.