Documentation
¶
Overview ¶
Package service enhances service orchestration by grouping related functionality, wrapping functions to support context-aware execution and add lifecycle-oriented functionality like signal handling in cloud-native environments.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Context ¶ added in v0.1.20
func Context() (context.Context, context.CancelFunc)
Context creates a new context with a cancel function that listens for SIGTERM, SIGINT, SIGQUIT, and SIGKILL signals.
func RegisterOnContextDone ¶ added in v0.1.20
RegisterOnContextDone waits for the context to be done and then calls the function.
Types ¶
type Function ¶
Function gathers together things that change for the same reasons. A context must be handled to be "cloud native" because it allows propagation of deadlines, cancellation signals, and other request-scoped values across API boundaries and between processes. This ensures efficient resource utilization and proper handling of asynchronous workflows in distributed systems.
func Wrap ¶
Wrap converts a simple function into one that respects a provided context. This enables the wrapped function to respond to context cancellation or timeout.
Example ¶
package main
import (
"context"
"fmt"
"github.com/andygeiss/cloud-native-utils/service"
)
func main() {
// Wrap turns a plain function into one that honours a context.
double := service.Wrap(func(n int) (int, error) { return n * 2, nil })
out, err := double(context.Background(), 21)
fmt.Println(out, err)
// A cancelled context stops the call before the function runs.
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err = double(ctx, 21)
fmt.Println(err)
}
Output: 42 <nil> context canceled