Register and run a background worker
masterTo create a worker, define a function with the signature func(string, ...interface{}) error. Register this function using goworker.Register("ClassName", functionName) and start the worker loop by calling goworker.Work().
package main
import (
"fmt"
"github.com/benmanns/goworker"
)
func myFunc(queue string, args ...interface{}) error {
fmt.Printf("From %s, %v\n", queue, args)
return nil
}
func init() {
goworker.Register("MyClass", myFunc)
}
func main() {
if err := goworker.Work(); err != nil {
fmt.Println("Error:", err)
}
}