D
D
Dmitry Shnyrev2014-11-15 22:43:10
go
Dmitry Shnyrev, 2014-11-15 22:43:10

How do you debug a web application in Go?

Another question for Go :)
How do you debug a web application in Go?
Share your recipes.
For now, I'm just using glog, which is configured to output to console. The size of the displayed information began to grow and it became very inconvenient to poke around in a footcloth of gray text in search of the desired line. I do not think that the development of serious applications is conducted in this way.
(do not offer frameworks, only separate libraries)
I searched the net, found one of the options - craig.is/writing/chrome-logger for debugging information output directly to the browser. There's even something for Go.
What else can be used?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SilentFl, 2014-11-17
@dmnBrest

There is also such a standard package as expvar , it produces a json structure along the path /debug/vars
Publish the necessary variables - and you can see their state at any time, and up to the heap state of memory.

D
Dmitry Shnyrev, 2014-11-16
@dmnBrest

I threw in a simple way, probably according to this principle all loggers work, which display beautiful panels with debugging information in the browser.
in the request handler, an array of strings is created, to which messages are added (in the future, the array of strings can be complicated and made into an array of structures that will contain the message type and text).
at the end, after all the outputs, the browser add another render of a special template (for the error block) to which to pass this array. It will turn out that an additional block with debugging information will be added to your page, which can already be decorated in the template using css.

var dLog []string
dLog = append(dLog, "test message 1")
dLog = append(dLog, "test message 1")
dLog = append(dLog, "test message 1")
...
err = templates["dlog"].ExecuteTemplate(w, "base", dLog)

sample
{{ define "base" }}
<hr/>
<div style="color: #FF0000;">
    <h2>Debug log:</h2>
    {{ range . }}
        <p>{{.}}</p>
    {{ end }}
</div>
{{ end }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question