debug

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2023 License: MIT Imports: 2 Imported by: 1

README

go-debug

This library provides a very simple method for compile-time or runtime determined debug checks, set using build tags.

The compile-time checks use Go constants, so when disabled your debug code will not be compiled.

The possible build tags are:

  • "debug" || "" = debug determined at compile-time

  • "debugenv" = debug determined at runtime using the $DEBUG environment variable

An example for how this works in practice can be seen by the following code:

func main() {
	println("debug.DEBUG() =", debug.DEBUG())
}
# Debug determined at compile-time, it is disabled
$ go run .
debug.DEBUG() = false

# Debug determined at compile-time, it is enabled
$ go run -tags=debug .
debug.DEBUG() = true

# Debug determined at runtime, $DEBUG is not set
$ go run -tags=debugenv .
debug.DEBUG() = false

# Debug determined at runtime, $DEBUG is set
$ DEBUG=y go run -tags=debugenv .
debug.DEBUG() = true

Documentation

Index

Constants

View Source
const DEBUG = false

DEBUG returns whether debugging is enabled.

Variables

This section is empty.

Functions

func BuildInfo added in v1.2.0

func BuildInfo(name string) string

BuildInfo will return a useful new-line separated build info string for current binary, setting name as given value.

func Run

func Run(fn func())

Run will only call fn if DEBUG is enabled.

func ServePprof added in v1.1.0

func ServePprof(addr string) error

ServePprof will start an HTTP server serving /debug/pprof only if debug enabled.

func WithPprof added in v1.1.0

func WithPprof(handler http.Handler) http.Handler

WithPprof will add /debug/pprof handling (provided by "net/http/pprof") only if debug enabled.

Types

This section is empty.

Jump to

Keyboard shortcuts

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