mode

package module
v0.0.0-...-9703805 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 2 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mode

Mode is a simple Golang package designed to allow code to run in debug, release, or test mode.

The idea is that code can conditional code using mode.Debug() and only perform certain activities when the code is not in release mode.

Specifying A Mode

To specify the mode to compile the code under, you use build tags.

To compile in debug mode, add -tags debug to go build.

To compile in release mode, add -tags release to go build.

Default Mode

By default, mode assumes the mode is release unless specified or detected otherwise. This matches the default semantics of Go programs today.

Test detection

Mode can automatically determine if the code is running via go test.

Starting with Go 1.21, the testing package can safely be imported by non-test packages, and so that is used to call testing.Testing(). Otherwise, at runtime, mode checks for the test flags.

Documentation

Index

Constants

View Source
const (
	ReleaseMode = "release"
	DebugMode   = "debug"
	TestMode    = "test"
)

Variables

View Source
var (
	// DefaultMode is the mode that the program should become if there
	// is no mode yet set.
	DefaultMode string
)

Functions

func Assert

func Assert(val bool, reason string)

If val is not true and the mode is debug, panic with the given message.

func Debug

func Debug() bool

Debug returns true if the current mode is not release.

func Mode

func Mode() string

Mode returns the current mode.

Types

This section is empty.

Jump to

Keyboard shortcuts

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