Go MIT

q

Quick and dirty debugging output for tired Go programmers

R

ryboe

Dernière activité 13 sept. 2026
ryboe/q

1,5 k

étoiles

69

forks

2

issues ouvertes

debuggergogolang

Ce README est souvent en anglais.

q

Go Report Card PkgGoDev

q is a better way to do print statement debugging.

Type q.Q instead of fmt.Printf and your variables will be printed like this:

q output examples

Why is this better than fmt.Printf?

  • Faster to type
  • Pretty-printed vars and expressions
  • Easier to see inside structs
  • Doesn't go to noisy-ass stdout. It goes to $TMPDIR/q.
  • Pretty colors!

Basic Usage

import "q"
...
q.Q(a, b, c)

For best results, dedicate a terminal to tailing $TMPDIR/q while you work.

Install

git clone https://github.com/ryboe/q "$(go env GOPATH)"/src/q

Put these functions in your shell config. Typing qq or rmqq will then start tailing $TMPDIR/q.

qq() {
    clear

    logpath="$TMPDIR/q"
    if [[ -z "$TMPDIR" ]]; then
        logpath="/tmp/q"
    fi

    if [[ ! -f "$logpath" ]]; then
        echo 'Q LOG' > "$logpath"
    fi

    tail -100f -- "$logpath"
}

rmqq() {
    logpath="$TMPDIR/q"
    if [[ -z "$TMPDIR" ]]; then
        logpath="/tmp/q"
    fi
    if [[ -f "$logpath" ]]; then
        rm "$logpath"
    fi
    qq
}

You also can simply tail -f $TMPDIR/q, but it's highly recommended to use the above commands.

Editor Integration

VS Code / Zed

VS Code: Preferences > User Snippets > Go Zed: ~/.config/zed/snippets/go.json

"qq": {
    "prefix": "qq",
    "body": "q.Q($1) // DEBUG",
    "description": "Pretty-print to $TMPDIR/q",
}

Sublime Text

Tools > Developer > New Snippet

<snippet>
    <content><![CDATA[
q.Q($1) // DEBUG
]]></content>
    <tabTrigger>qq</tabTrigger>
    <scope>source.go</scope>
</snippet>

JetBrains GoLand

Settings > Editor > Live Templates

In Go, add a new template with:

  • Abbreviation: qq
  • Description: Pretty-print to $TMPDIR/q
  • Template text: q.Q($END$) // DEBUG
  • Applicable in: select the Go scope

Emacs

Add a new snippet file to the go-mode snippets directory ($HOME/.emacs.d/snippets/go-mode/qq). This should contain:

# -*- mode: snippet -*-
# name: qq
# key: qq
# --
q.Q(${1:...}) // DEBUG

Vim/NeoVim

For SirVer/ultisnips, use :UltiSnipsEdit to add the new snippet:

snippet qq "qq"
q.Q(${1:})
${2}
endsnippet

Haven't I seen this somewhere before?

Python programmers will recognize this as a Golang port of the q module by zestyping.

Ping does a great job of explaining q in his awesome lightning talk from PyCon 2013. Watch it! It's funny :)

ping's PyCon 2013 lightning talk

FAQ

Why q.Q?

It's quick to type and unlikely to cause naming collisions.

Is q.Q() safe for concurrent use?

Yes.

Projets similaires

Delve is a debugger for the Go programming language.

Godebuggergogolang
Ggo-delve
24,9 k étoiles2,2 k

Never use print for debugging again

Pythondebugdebuggerintrospection
Ccool-RR
16,6 k étoiles962

Dump any GO variable with ease

Godebugdumpformatting
Yyassinebenaid
223 étoiles4