toggle

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: MIT Imports: 5 Imported by: 0

README

Go Toggle

Simple library to add toggleable pieces of code that can be switched on or off in runtime or just at boot time

Documentation

Index

Examples

Constants

View Source
const (
	ToggleableExistsError   = err.Error("toggleable already exists")
	NotEnoughOptionsError   = err.Error("toggleables need at least 2 options to toggle")
	ToggleableNotFoundError = err.Error("toggleable does not exist")
	InvalidToggleError      = err.Error("toggle value is out of bounds for the toggleable")
)

Variables

This section is empty.

Functions

func Add

func Add(name string, options ...func() error) error

func Execute

func Execute(name string) error

func Run

func Run(name string, options ...func() error) error
Example
os.Args = []string{"app", "-TExampleRun", "1"}
env.Load() // For testing purposes the environment has to be reloaded after updating the cml arguments
_ = Add("ExampleRun", func() error {
	fmt.Println("1")
	return nil
}, func() error {
	fmt.Println("2")
	return nil
})
_ = Execute("ExampleRun")
_ = Toggle("ExampleRun", 0)
_ = Execute("ExampleRun")
_ = Run("ExampleRun", func() error {
	fmt.Println("2")
	return nil
}, func() error {
	fmt.Println("1")
	return nil
})
Output:

2
1
2

func Toggle

func Toggle(name string, toggle int) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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