hopwatch

package module
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 15 Imported by: 0

README

Hopwatch, a debugging tool for Go

Hopwatch is a simple tool in HTML5 that can help debug Go programs. It works by communicating to a WebSockets based client in Javascript. When your program calls the Break function, it sends debug information to the browser page and waits for user interaction. Using the functions Display, Printf or Dump (go-spew), you can log information on the browser page. On the hopwatch page, the developer can view debug information and choose to resume the execution of the program.

First announcement

How

Distributed (work in progress)

Hopwatch can be used in a distributed services architecture to hop and trace between services following an incoming request to downstream service.

Consider the setup where the browser is sending a HTTP request to a GraphQL endpoint which calls a gRPC backend service, which calls a PostgreSQL Database server to perform a query. The result of that query needs to be transformed into a gRPC response which in turn needs to be transformed into a GraphQL response before transporting it back to the browser.

We want to jump from client to server to server and back, for a given request. To signal the upstream services that it should break on this request, the request must be annotated using a special HTTP header x-hopwatch : your-correlation-name.

Each upstream server must have the hopwatch agent package included:

import _ "github.com/momo182/hopwatch/agent"

© 2012-2022, http://ernestmicklei.com. MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Break

func Break(conditions ...bool)

Break suspends the execution of the program and waits for an instruction from the debugger (e.g. Resume). Break is only effective if all (if any) conditions are true. The program will resume otherwise.

func Disable

func Disable()

func Enable

func Enable()

Types

type Watchpoint

type Watchpoint struct {
	// contains filtered or unexported fields
}

watchpoint is a helper to provide a fluent style api. This allows for statements like hopwatch.Display("var",value).Break()

func CallerOffset

func CallerOffset(offset int) *Watchpoint

CallerOffset (default=2) allows you to change the file indicator in hopwatch. Use this method when you wrap the .CallerOffset(..).Display(..).Break() in your own function.

func Display

func Display(nameValuePairs ...interface{}) *Watchpoint

Display sends variable name,value pairs to the debugger. The parameter nameValuePairs must be even sized.

func Dump

func Dump(a ...interface{}) *Watchpoint

Dump displays the passed parameters with newlines and additional debug information such as complete types and all pointer addresses used to indirect to the final value. Delegates to spew.Fdump, see http://godoc.org/github.com/davecgh/go-spew/spew#Dump

func Dumpf

func Dumpf(format string, a ...interface{}) *Watchpoint

Dumpf formats and displays the passed parameters with newlines and additional debug information such as complete types and all pointer addresses used to indirect to the final value. delegates to spew.Fprintf, see http://godoc.org/github.com/davecgh/go-spew/spew#Dump

func Printf

func Printf(format string, params ...interface{}) *Watchpoint

Printf formats according to a format specifier and writes to the debugger screen. It returns a new Watchpoint to send more or break.

func (Watchpoint) Break

func (w Watchpoint) Break(conditions ...bool)

Break halts the execution of the program and waits for an instruction from the debugger (e.g. Resume). Break is only effective if all (if any) conditions are true. The program will resume otherwise.

func (*Watchpoint) CallerOffset

func (w *Watchpoint) CallerOffset(offset int) *Watchpoint

CallerOffset (default=2) allows you to change the file indicator in hopwatch.

func (*Watchpoint) Display

func (w *Watchpoint) Display(nameValuePairs ...interface{}) *Watchpoint

Display sends variable name,value pairs to the debugger. Values are formatted using %#v. The parameter nameValuePairs must be even sized.

func (*Watchpoint) Dump

func (w *Watchpoint) Dump(a ...interface{}) *Watchpoint

Dump displays the passed parameters with newlines and additional debug information such as complete types and all pointer addresses used to indirect to the final value. Delegates to spew.Fdump, see http://godoc.org/github.com/davecgh/go-spew/spew#Dump

func (*Watchpoint) Dumpf

func (w *Watchpoint) Dumpf(format string, a ...interface{}) *Watchpoint

Dumpf formats and displays the passed parameters with newlines and additional debug information such as complete types and all pointer addresses used to indirect to the final value. Delegates to spew.Fprintf, see http://godoc.org/github.com/davecgh/go-spew/spew#Dump

func (*Watchpoint) Printf

func (w *Watchpoint) Printf(format string, params ...interface{}) *Watchpoint

Printf formats according to a format specifier and writes to the debugger screen.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL