ogimpl

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Assert  = "Assert"
	CMD     = "CMD"
	HttpReq = "HttpReq"

	Queue    = "Queue"
	Choose   = "Choose"
	Parallel = "Parallel"
	Race     = "Race"

	Async     = "Async"
	Condition = "Condition"
	Loop      = "Loop"
	Retry     = "Retry"
	Silent    = "Silent"
	Timeout   = "Timeout"
	Trace     = "Trace"
	Delay     = "Delay"
	Debug     = "Debug"
)
View Source
const (
	AllowRead = 1 << iota
	AllowWrite
)

Variables

View Source
var AssertNodeFactory = func() ogcore.Node {
	return &AssertNode{}
}
View Source
var AsyncWrapperFactory = func() ogcore.Node {
	return &AsyncWrapper{}
}
View Source
var ChooseClusterFactory = func() ogcore.Node {
	return &ChooseCluster{}
}
View Source
var CmdNodeFactory = func() ogcore.Node {
	return &CmdNode{}
}
View Source
var ConditionWrapperFactory = func() ogcore.Node {
	return &ConditionWrapper{}
}
View Source
var DebugWrapperFactory = func() ogcore.Node {
	return &DebugWrapper{}
}
View Source
var DelayWrapperFactory = func() ogcore.Node {
	return &DelayWrapper{}
}
View Source
var ErrTimeout = errors.New("the running time exceeds the limit")
View Source
var HttpReqNodeFactory = func() ogcore.Node {
	return &HttpReqNode{}
}
View Source
var LoopWrapperFactory = func() ogcore.Node {
	return &LoopWrapper{LoopTimes: 1}
}
View Source
var ParallelClusterFactory = func() ogcore.Node {
	return &ParallelCluster{}
}
View Source
var QueueClusterFactory = func() ogcore.Node {
	return &ograph.BaseCluster{}
}
View Source
var RaceClusterFactory = func() ogcore.Node {
	return &RaceCluster{}
}
View Source
var RetryWrapperFactory = func() ogcore.Node {
	return &RetryWrapper{MaxRetryTimes: 1}
}
View Source
var SilentWrapperFactory = NewSilentWrapper
View Source
var TimeoutWrapperFactory = func() ogcore.Node {
	return &TimeoutWrapper{}
}
View Source
var TraceWrapperFactory = func() ogcore.Node {
	return &TraceWrapper{}
}

Functions

func AssertOp added in v0.8.0

func AssertOp(expr string) ograph.ElementOption

func ChooseOp added in v0.8.0

func ChooseOp(expr string, candidates ...*ograph.Element) ograph.ElementOption

func ConditionOp added in v0.7.0

func ConditionOp(expr string) ograph.ElementOption

func DelayOp

func DelayOp(wait time.Duration) ograph.ElementOption

func LoopOp

func LoopOp(n int) ograph.ElementOption

func LoopWhileOp added in v0.7.0

func LoopWhileOp(expr string) ograph.ElementOption

func NewAssertNodeFactory added in v0.8.0

func NewAssertNodeFactory(
	assertFn func(ctx context.Context, state ogcore.State) (bool, error),
) func() ogcore.Node

func NewChooseClusterFactory

func NewChooseClusterFactory(
	chooseFn func(ctx context.Context, state ogcore.State) int,
) func() ogcore.Node

func NewConditionWrapperFactory

func NewConditionWrapperFactory(
	cond func(ctx context.Context, state ogcore.State) bool,
) func() ogcore.Node

func NewRetryWrapper

func NewRetryWrapper(times int) ogcore.Node

func NewSilentWrapper

func NewSilentWrapper() ogcore.Node

func NewTimeoutWrapper

func NewTimeoutWrapper(timeout time.Duration) ogcore.Node

func RetryOp

func RetryOp(n int) ograph.ElementOption

func SetTraceId

func SetTraceId(state ogcore.State, id string)

func TimeoutOp

func TimeoutOp(dur time.Duration) ograph.ElementOption

Types

type AssertNode added in v0.8.0

type AssertNode struct {
	ograph.BaseNode

	AssertExpr string

	AssertFn func(ctx context.Context, state ogcore.State) (bool, error)
}

func (*AssertNode) Init added in v0.8.0

func (node *AssertNode) Init(params map[string]any) error

func (*AssertNode) Run added in v0.8.0

func (node *AssertNode) Run(ctx context.Context, state ogcore.State) error

type AsyncWrapper

type AsyncWrapper struct {
	ograph.BaseWrapper
	*slog.Logger
}

func (*AsyncWrapper) Run

func (wrapper *AsyncWrapper) Run(ctx context.Context, state ogcore.State) error

type ChooseCluster

type ChooseCluster struct {
	ograph.BaseCluster
	*slog.Logger

	ChooseExpr string

	ChooseFn func(ctx context.Context, state ogcore.State) int
}

func (*ChooseCluster) Init added in v0.7.0

func (cluster *ChooseCluster) Init(params map[string]any) error

func (*ChooseCluster) Run

func (cluster *ChooseCluster) Run(ctx context.Context, state ogcore.State) error

type CmdNode

type CmdNode struct {
	ograph.BaseNode
	*slog.Logger

	Cmd  []string
	Env  []string
	Dir  string
	Path string
}

func (*CmdNode) CmdIsAllowed

func (node *CmdNode) CmdIsAllowed() bool

func (*CmdNode) Run

func (node *CmdNode) Run(ctx context.Context, state ogcore.State) error

type ConditionWrapper

type ConditionWrapper struct {
	ograph.BaseWrapper

	ConditionExpr string

	Condition func(ctx context.Context, state ogcore.State) bool
}

func (*ConditionWrapper) Init added in v0.7.0

func (wrapper *ConditionWrapper) Init(params map[string]any) error

func (*ConditionWrapper) Run

func (wrapper *ConditionWrapper) Run(ctx context.Context, state ogcore.State) error

type DebugWrapper

type DebugWrapper struct {
	ograph.BaseWrapper
	*slog.Logger
}

func (*DebugWrapper) Run

func (wrapper *DebugWrapper) Run(ctx context.Context, state ogcore.State) error

type DelayWrapper

type DelayWrapper struct {
	ograph.BaseWrapper

	Wait  time.Duration
	Until time.Time
}

func (*DelayWrapper) Run

func (wrapper *DelayWrapper) Run(ctx context.Context, state ogcore.State) error

type FastState

type FastState struct {
	// contains filtered or unexported fields
}

func NewFastState

func NewFastState() *FastState

func (*FastState) Get

func (state *FastState) Get(key any) (any, bool)

func (*FastState) Set

func (state *FastState) Set(key any, val any)

func (*FastState) Update

func (state *FastState) Update(key any, updateFunc func(val any) any)

type GuardState

type GuardState struct {
	// contains filtered or unexported fields
}

func NewGuardState

func NewGuardState(state ogcore.State, guard func(key any) (flag int)) *GuardState

func (*GuardState) Get

func (state *GuardState) Get(key any) (any, bool)

func (*GuardState) Set

func (state *GuardState) Set(key any, val any)

func (*GuardState) Update

func (state *GuardState) Update(key any, updateFunc func(val any) any)

type HookState

type HookState struct {
	Base ogcore.State

	Hooks []StateHookFn
}

func NewHookState

func NewHookState(base ogcore.State, hooks ...StateHookFn) *HookState

func (*HookState) Get

func (state *HookState) Get(key any) (any, bool)

func (*HookState) Set

func (state *HookState) Set(key any, val any)

func (*HookState) Update

func (state *HookState) Update(key any, updateFunc func(val any) any)

type HttpReqNode

type HttpReqNode struct {
	ograph.BaseNode
	*slog.Logger

	Method      string
	Url         string
	ContentType string
	Body        *string
	BodyTpl     *string
}

func (*HttpReqNode) Run

func (node *HttpReqNode) Run(ctx context.Context, state ogcore.State) error

type LoopWrapper

type LoopWrapper struct {
	ograph.BaseWrapper

	LoopTimes    int
	LoopInterval time.Duration

	ConditionExpr string
	Condition     func(ctx context.Context, state ogcore.State) bool
}

func (*LoopWrapper) Init added in v0.7.0

func (wrapper *LoopWrapper) Init(params map[string]any) error

func (*LoopWrapper) Run

func (wrapper *LoopWrapper) Run(ctx context.Context, state ogcore.State) error

type OverlayState

type OverlayState struct {
	Upper map[any]any
	Lower ogcore.State

	sync.RWMutex
}

func NewOverlayState

func NewOverlayState(state ogcore.State) *OverlayState

func (*OverlayState) Get

func (state *OverlayState) Get(key any) (any, bool)

func (*OverlayState) Set

func (state *OverlayState) Set(key any, val any)

func (*OverlayState) Sync

func (state *OverlayState) Sync()

func (*OverlayState) Update

func (state *OverlayState) Update(key any, updateFunc func(val any) any)

type ParallelCluster

type ParallelCluster struct {
	ograph.BaseCluster
}

func (*ParallelCluster) Run

func (cluster *ParallelCluster) Run(ctx context.Context, state ogcore.State) error

type RaceCluster

type RaceCluster struct {
	ograph.BaseCluster
	*slog.Logger

	StateIsolation bool
}

func (*RaceCluster) Run

func (cluster *RaceCluster) Run(ctx context.Context, state ogcore.State) error

type RetryWrapper

type RetryWrapper struct {
	ograph.BaseWrapper
	*slog.Logger

	MaxRetryTimes int
	RetryDelay    *time.Duration
}

func (*RetryWrapper) Run

func (wrapper *RetryWrapper) Run(ctx context.Context, state ogcore.State) error

type SilentWrapper

type SilentWrapper struct {
	ograph.BaseWrapper
	*slog.Logger
}

func (*SilentWrapper) Run

func (wrapper *SilentWrapper) Run(ctx context.Context, state ogcore.State) error

type StateHookFn

type StateHookFn func(state ogcore.State, event string, key any, completed bool)

type TimeoutWrapper

type TimeoutWrapper struct {
	ograph.BaseWrapper

	Timeout time.Duration
}

func (*TimeoutWrapper) Run

func (wrapper *TimeoutWrapper) Run(ctx context.Context, state ogcore.State) error

type TraceWrapper

type TraceWrapper struct {
	ograph.BaseWrapper
	*slog.Logger
}

func (*TraceWrapper) Run

func (wrapper *TraceWrapper) Run(ctx context.Context, state ogcore.State) error

type Visitor added in v0.7.0

type Visitor struct {
	Identifiers []string
}

func (*Visitor) Visit added in v0.7.0

func (v *Visitor) Visit(node *ast.Node)

Jump to

Keyboard shortcuts

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