debug

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: Apache-2.0 Imports: 9 Imported by: 4

README

debug is a simple library for Go that allows you to optionally debug your executable based on env variables.

Usage

Simply add debug.Self() to your main function as shown below:

import (
    "github.com/edwarnicke/debug"
)

func main() {
    if err := debug.Self(); err != nil {
        log.Infof("%s", err)
    }
...
}

will cause your application to log out:

Setting env variable DLV_LISTEN_{{executable name}} to a valid dlv '--listen' value will cause the dlv debugger to execute this binary and listen as directed.

thus informing you of what env variable to set to a valid dlv listener value to trigger debugging.

So if your application where named 'forwarder', you'd see:

Setting env variable DLV_LISTEN_FORWARDER to a valid dlv '--listen' value will cause the dlv debugger to execute this binary and listen as directed.

and setting the env variable:

export DLV_LISTEN_FORWARDER=:50000

would cause your applicaton to exec itself over with dlv with arguments to run the application itself.

Documentation

Overview

Package debug provides a very simple function that, if executed will replace the executable with dlv running the executable and listening on the port specified by an environment variable.

Example:
if err := debug.Self(); err != nil {
   fmt.Println(err)
}

Index

Constants

View Source
const (
	// Dlv - name of Dlv executable, also used as default prefix to env variable, ie, DLV_
	Dlv = "dlv"
	// Listen - string used as default second part of env variable, ie, _PORT in DLV_PORT
	Listen = "listen"
)

Variables

This section is empty.

Functions

func Self

func Self(envVariableParts ...string) error

Self - replaces executable with dlv running the executable and listening on a port

envVariableParts - variadic list of 'pieces' to be transformed into the
                   env variable indicating where dlv should listen.
                   Default: If no envVariableParts are provided, env variable
                            defaults to []string{Dlv,Listen,path.Base(os.Args[0])}
                            which is DLV_PORT_<name of executable>

Types

This section is empty.

Jump to

Keyboard shortcuts

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