-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdoc.go
72 lines (50 loc) · 2.46 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2012+ ernestmicklei.com. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
/*
Hopwatch is a debugging tool for Go programs.
Hopwatch uses a (embedded) HTML5 application to connect to your program (using a Websocket).
Using Hopwatch requires adding function calls at points of interest that allow you to watch program state and suspend the program.
On the Hopwatch page, you can view debug information (file:line,stack) and choose to resume the execution of your program.
You can provide more debug information using the Display and Dump functions which take an arbitrary number of variables.
The Display and Dump functions do not suspend the program ; it is like having logging information in the browser.
Usage:
import (
// use a tag
"gopkg.in/emicklei/hopwatch.v1"
// or use the master
// "github.com/emicklei/hopwatch"
)
func foo() {
bar := "john"
// suspends execution until hitting "Resume" in the browser
hopwatch.Display("foo", bar).Break()
}
Connect:
The Hopwatch debugger is automatically started on http://localhost:23456/hopwatch.html.
Your browser must support WebSockets. It has been tested with Chrome and Safari on a Mac.
Other code examples:
// zero or more conditions ; conditionally suspends program (or goroutine)
hopwatch.Break(i > 10, j < 100)
// zero or more name,value pairs ; no program suspend
hopwatch.Display("i",i , "j",j")
// print any formatted string ; no program suspend
hopwatch.Printf("result=%v", result)
// display detailed (type, nesting) information using https://github.com/davecgh/go-spew
hopwatch.Dump(myVar1)
// format and display detailed (type, nesting) information using https://github.com/davecgh/go-spew
hopwatch.Dumpf("myVar1: %v -- myVar2: %+v", myVar1, myVar2)
Flags:
-hopwatch if set to false then hopwatch is disabled.
-hopwatch.open if set to false then hopwatch will not try to open the debugger page on startup.
-hopwatch.break if set to false then hopwatch will not suspend the program when Break(..) is called.
-hopwatch.host tcp hostname of the listener address (default = localhost).
-hopwatch.port tcp port of the listener address (default = 23456).
Install from master:
go get -u github.com/emicklei/hopwatch
Resources:
https://github.com/emicklei/hopwatch (project)
http://ernestmicklei.com/2012/12/14/hopwatch-a-debugging-tool-for-go/ (blog)
(c) 2012-2022+, Ernest Micklei. MIT License
*/
package hopwatch