Help us shape the future of Go! Take the 2026 Go Developer Survey

utilfx

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 3 Imported by: 4

README

utilfx

CI Go Reference

Small helpers for common Uber Fx dependency-wiring patterns.

Installation

go get github.com/uchaloop/utilfx

Bind

Expose a concrete service through an interface:

fx.Provide(
	makeService,
	utilfx.Bind[Handler, *Service],
)

The concrete service remains available in the graph. An incompatible binding is reported as an Fx constructor error.

Value groups

Register constructors in one group:

utilfx.Grouped(
	"http_handlers",
	makeHealthHandler,
	makeMetricsHandler,
)

Register implementations of an interface:

utilfx.GroupedAs[Handler](
	"http_handlers",
	makeHealthHandler,
	makeMetricsHandler,
)

Build a group name for a named instance:

group := utilfx.GroupName("database_options", "analytics")

utilfx.GroupedFor(
	"analytics",
	"database_options",
	makeOption,
)

Grouped, GroupedAs, and GroupedFor ignore nil constructors.

Fx tags

Build readable annotation tags:

fx.Annotate(
	makeClient,
	fx.ParamTags(utilfx.OptionalNameTag("analytics")),
	fx.ResultTags(utilfx.NameTag("analytics")),
)

For value groups:

fx.Annotate(
	makeHandler,
	fx.ResultTags(utilfx.GroupTag("http_handlers")),
)

Available helpers:

  • NameTag
  • OptionalNameTag
  • GroupTag
  • GroupName

ModuleFor

Select the default module for an empty name and a named module otherwise:

func moduleFor(name string) fx.Option {
	return utilfx.ModuleFor(name, Module, makeNamedModule)
}

Acknowledgements

I am grateful to the authors of Uber Fx. Their work made this library possible.

License

MIT

Documentation

Overview

Package utilfx contains focused helpers for Fx dependency wiring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[Contract any, Impl any](impl Impl) (Contract, error)

Bind exposes implementation as contract. It can be passed directly to fx.Provide and replaces adapters of the form:

func(service *Service) Handler { return service }

An incompatible implementation is reported as an Fx constructor error.

func GroupName

func GroupName(group, name string) string

GroupName returns group when name is empty. Otherwise it returns a group name in the form "group:name".

func GroupTag

func GroupTag(group string) string

GroupTag returns an Fx tag for a value group.

func Grouped

func Grouped(group string, ctors ...any) fx.Option

Grouped provides constructors whose results belong to the same Fx value group. Nil constructors are ignored.

func GroupedAs

func GroupedAs[T any](group string, ctors ...any) fx.Option

GroupedAs provides constructors as T in the same Fx value group. Each constructor result must implement T. Nil constructors are ignored.

func GroupedFor

func GroupedFor(name, group string, ctors ...any) fx.Option

GroupedFor provides constructors in a group composed from group and name. Nil constructors are ignored.

func ModuleFor

func ModuleFor(name string, def fx.Option, mk func(string) fx.Option) fx.Option

ModuleFor returns the default module when name is empty. Otherwise it builds the named module.

func NameTag

func NameTag(name string) string

NameTag returns an Fx tag for a named dependency or result.

func OptionalNameTag

func OptionalNameTag(name string) string

OptionalNameTag returns an Fx tag for an optional named dependency.

Types

This section is empty.

Jump to

Keyboard shortcuts

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