Documentation
¶
Overview ¶
Package logic groups kit setters and applies them under control-flow helpers. It is the containerkit equivalent of go-contain's tools package.
c := kit.NewContainer(
logic.Group(
kit.Name("api"),
kit.Image("alpine:latest"),
logic.When(isProd, kit.Env("CACHE", "1")),
),
)
Helpers return kit.Grouped, which implements every kit option interface, so a group can be passed to NewContainer, NewService, nested Health/Volume scopes, Engine actions, and Compose runtime methods.
Index ¶
- func Case(cond bool, opts ...any) kit.Grouped
- func CaseFn(pred Predicate, opts ...any) kit.Grouped
- func Default(opts ...any) kit.Grouped
- func Each[T any](items []T, f func(i int, item T) any) kit.Grouped
- func EachKV[K comparable, V any](items map[K]V, f func(k K, v V) any) kit.Grouped
- func Group(opts ...any) kit.Grouped
- func Map[T any](items []T, f func(item T) any) kit.Grouped
- func On[T comparable](got, want T, opts ...any) kit.Grouped
- func OnlyIf(check Check, opt any) kit.Grouped
- func Switch(cases ...kit.Grouped) kit.Grouped
- func Unless(cond bool, opts ...any) kit.Grouped
- func UnlessFn(pred Predicate, opts ...any) kit.Grouped
- func When(cond bool, opts ...any) kit.Grouped
- func WhenElse(cond bool, thenOpt, elseOpt any) kit.Grouped
- func WhenElseFn(pred Predicate, thenOpt, elseOpt any) kit.Grouped
- func WhenFn(pred Predicate, opts ...any) kit.Grouped
- type Check
- type Predicate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EachKV ¶
func EachKV[K comparable, V any](items map[K]V, f func(k K, v V) any) kit.Grouped
EachKV maps each key and value to a setter and groups them. A nil map or factory is a no-op. Iteration order follows the map.
func Group ¶
Group combines setters into one. Errors from the inner setters are joined. Nil setters are skipped.
func On ¶
func On[T comparable](got, want T, opts ...any) kit.Grouped
On is a Switch branch taken when got equals want.
func OnlyIf ¶
OnlyIf applies the setter when check returns true. A failed check returns its error instead of skipping. A nil check is an error.
func WhenElseFn ¶
WhenElseFn applies thenOpt when pred() is true and elseOpt otherwise.
Types ¶
type Check ¶
Check is a fallible predicate. Unlike Predicate, a non-nil error stops apply rather than skipping the setter.
type Predicate ¶
type Predicate func() bool
Predicate is a condition evaluated when a setter is applied, not when it is constructed. Use it for flags, environment, and other ambient checks.
func And ¶
And is true when every value is true. The result is a Predicate so it can be passed to WhenFn.