function

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ToolFunc

type ToolFunc[In any, Out any] func(context.Context, In) (Out, error)

ToolFunc defines the signature for a generic Go function that can be wrapped as a tool. It accepts a context and a strongly-typed input, and returns a strongly-typed output and an error.

type Wrapper

type Wrapper[In any, Out any] struct {
	// contains filtered or unexported fields
}

Wrapper adapts a generic ToolFunc into the universal core.Action interface. This allows any regular Go function to be managed, supervised, and traced by Manglekit.

func New

func New[In any, Out any](name string, fn ToolFunc[In, Out]) *Wrapper[In, Out]

New creates a new Action wrapper for the provided function.

Parameters:

  • name: The unique name of the action.
  • fn: The function to wrap.

Returns:

  • A pointer to the initialized Wrapper.

func (*Wrapper[In, Out]) Execute

func (w *Wrapper[In, Out]) Execute(ctx context.Context, input core.Envelope) (core.Envelope, error)

Execute performs the action logic. It automatically handles type assertion from the generic Envelope payload to the function's input type, and wraps the function's output back into an Envelope.

Parameters:

  • ctx: The execution context.
  • input: The input Envelope.

Returns:

  • The result Envelope, or an error if type assertion or execution fails.

func (*Wrapper[In, Out]) Metadata

func (w *Wrapper[In, Out]) Metadata() core.ActionMetadata

Metadata returns the action's metadata (name and type "function").

func (*Wrapper[In, Out]) SetContentType

func (w *Wrapper[In, Out]) SetContentType(ct core.ContentType)

SetContentType allows configuring the expected input content type (e.g., JSON vs Struct).

Jump to

Keyboard shortcuts

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