function

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

fx/modules/bootstrap/function

fx module that runs a bootstrap/function handler through the adapter commands provided in the boostrap.function.adapters group (BSFunctionAdaptersGroupKey) — cloudevents HTTP, NATS, Pub/Sub, Kafka.

fxfact.NewApp(
	fx.Provide(func() function.Handler[*event.Event] { return handle }),
	cehttp.Module[*event.Event](),
	functionfx.Module[*event.Event](middlewares),
).Run()

T must be *event.Event or []*event.Event.

The function runs the middlewares given to Module, then the []middleware.AnyErrorMiddleware[T] provided under the name MiddlewaresName (bootstrap.function.middlewares), when there is one. That is how a builder app passes the middlewares of its @Function:

fx.Provide(fx.Annotate(
	func() []middleware.AnyErrorMiddleware[*event.Event] { return mws },
	fx.ResultTags(`name:"`+functionfx.MiddlewaresName+`"`),
))

Lifecycle

  • OnStart — Function.Run runs in a goroutine, so fx.New returns and app.Run() listens for SIGINT/SIGTERM.
  • OnStop — the context passed to Run (and to the adapter command) is cancelled; the hook waits for Run to return, bounded by the stop context (fx's stop timeout), and returns the context error if it does not.
  • Run ends on its own (no stop requested) — the app is shut down with exit code 0 on success, or 1 when Run returned an error (logged).

Documentation

Index

Constants

View Source
const (
	BSFunctionAdaptersGroupKey = "boostrap.function.adapters"

	// MiddlewaresName names the optional []middleware.AnyErrorMiddleware[T]
	// the function runs after the middlewares given to Module, in order.
	// builder provides it for @Function(middlewares=[...]).
	MiddlewaresName = "bootstrap.function.middlewares"
)
View Source
const (
	Root = bootstrap.Root + ".function"
)

Variables

This section is empty.

Functions

func Module

func Module[T any](m []middleware.AnyErrorMiddleware[T]) fx.Option

Module fx module for bootstrap function. The function runs from the app's OnStart and its context is cancelled on OnStop, so app.Run handles SIGTERM gracefully; when the function ends on its own the app shuts down, with exit code 1 if it failed. The function runs m, then the middlewares named MiddlewaresName when the app provides them.

Types

This section is empty.

Directories

Path Synopsis
contrib/cloud.google.com/pubsub
Package pubsub declares, once, the config the Pub/Sub v1 and v2 function adapter fx modules share: whether the adapter is on and which version it is.
Package pubsub declares, once, the config the Pub/Sub v1 and v2 function adapter fx modules share: whether the adapter is on and which version it is.

Jump to

Keyboard shortcuts

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