Skip to content

Examples

Aliasgar Khimani edited this page Dec 30, 2021 · 4 revisions

Here's an example program making use of the puffgo package:


package main

import (
	"fmt"
	"time"

	"github.com/ARaChn3/puffgo"
)

func main() {
	// interval is the interval between listening cycles of the event listener
	interval := 500 * time.Millisecond

	// First we need to declare an event-listener for the logic-bomb:
	// We can do so using the NewListener() method
	el := puffgo.NewListener(&interval, triggerFunction)

	// We can now create the logic-bomb using the NewBomb method:
	lb := puffgo.NewBomb(*el, executionFunction)

	// Next, we need to arm the bomb for it to go off when it detects
	// a signal from the event-listener
	lb.Arm()
}

// This can be anything.
// For the sake of simplicity, let it be a simple function that returns true
func triggerFunction() bool {
	return true
}

// This is the function which is callled when the bomb goes off.
// For this example, we'll just make it print something
func executionFunction() {
	fmt.Println("BOOOOM!!")
}

You may change executionFunction as needed. The same goes for triggerFunction. What's the result? It's a logic bomb that can be programmed to detect and execute virtually anything upon being triggered.

Clone this wiki locally