Last active
January 8, 2026 08:40
-
-
Save hovsep/7f7c2da121a46556cd70485c75786643 to your computer and use it in GitHub Desktop.
FMesh chained api example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Builder pattern (all chained calls are invoked on the same object): | |
| p := component.New("processor"). | |
| WithDescription("main processor"). | |
| AddLabel("env", "prod"). | |
| AddLabel("tier", "backend"). | |
| AddInputs("in1", "in2"). | |
| AddOutputs("out1", "out2"). | |
| WithActivationFunc(func(this *component.Component) error { | |
| return nil | |
| }) | |
| // Seamless chained api pattern (different objects chained): | |
| filteredResults := mesh.ComponentByName("my-component"). // Pick a Component | |
| OutputByName("res"). // Jump to Port | |
| Signals(). // Now jump onto a signals Group | |
| Filter(func(s *signal.Signal) bool { | |
| return s.Labels().ValueIs("cluster", "k8s") | |
| }) | |
| // Check error whenever you want | |
| if filteredResults.HasChainableErr() { | |
| fmt.Println("Oh no! The chain errored", filteredResults.ChainableErr()) | |
| os.Exit(1) | |
| } | |
| // Continue chaining | |
| payload := filteredResults.First().PayloadOrNil() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment