gotomatic

module
v0.0.0-...-fcb0166 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2017 License: GPL-3.0

README

Build Status GoDoc

gotomatic

Gotomatic is both a library and a set of tools to deal with conditions.

All the condition types provided by gotomatic implement Condition which is a very simple, yet powerful interface.

All condition types are thread-safe and have a low-memory footprint. They rely on channels internally and are very effective.

Conditions can be composed logically (and, or, xor), negated, delayed or even set from external sources (commands, HTTP requests).

Here is a simple example:

package main

import (
	"time"

	"github.com/intelux/gotomatic/conditional"
)

func main() {
	// Create a new manual condition, which can be set programmatically.
	condition := conditional.NewManualCondition(false)
	defer condition.Close()

	// Set the condition in another goroutine.
	go condition.Set(true)

	// Wait for the condition to become true.
	condition.Wait(true)
}

Here is a more complex one:

package main

import (
	"time"

	"github.com/intelux/gotomatic/conditional"
	gtime "github.com/intelux/gotomatic/time"
)

func main() {
	// Create a new time condition, which is only set between 10:00 and 11:00.
	conditionA := conditional.NewTimeCondition(
		gtime.NewRecurrentMoment(
			time.Date(0, 1, 1, 10, 0, 0, 0, time.Local),
			time.Date(0, 1, 1, 11, 0, 0, 0, time.Local),
			gtime.FrequencyDay,
		)
	)

	// Create a new time condition, which is only set the first day of each month.
	conditionB := conditional.NewTimeCondition(
		gtime.NewRecurrentMoment(
			time.Date(0, 1, 1, 0, 0, 0, 0, time.Local),
			time.Date(0, 1, 2, 0, 0, 0, 0, time.Local),
			gtime.FrequencyMonth,
		)
	)

	// Create a new condition, which is only set the first day of each month,
	between 10:00 and 11:00.
	condition := conditional.NewCompositeCondition(conditional.OperatorAnd, conditionA, conditionB)
	defer condition.Close()

	// Wait for the condition to become true.
	condition.Wait(true)
}

Directories

Path Synopsis
Package conditional defines condition primitives and logic to ease writing of complex condition compositions.
Package conditional defines condition primitives and logic to ease writing of complex condition compositions.
Package configuration provides functions to create and load configurations.
Package configuration provides functions to create and load configurations.
Package executor implements executors for cut-off conditions.
Package executor implements executors for cut-off conditions.
Package time defines time-related types for conditions.
Package time defines time-related types for conditions.
Package trigger implements triggers for conditions.
Package trigger implements triggers for conditions.

Jump to

Keyboard shortcuts

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