Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ linters:

# Our own extras:
- errorlint
- modernize
- nolintlint # lints //nolint directives
- revive

Expand All @@ -28,11 +29,10 @@ linters:

# These govet checks are disabled by default, but they're useful.
govet:
enable:
- nilness
- reflectvaluecompare
- sortslice
- unusedwrite
enable-all: true
disable:
- fieldalignment
- shadow

goheader:
values:
Expand Down
14 changes: 7 additions & 7 deletions annotated.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ var (
// field used for embedding fx.In type in generated struct.
_inAnnotationField = reflect.StructField{
Name: "In",
Type: reflect.TypeOf(In{}),
Type: reflect.TypeFor[In](),
Anonymous: true,
}
// field used for embedding fx.Out type in generated struct.
_outAnnotationField = reflect.StructField{
Name: "Out",
Type: reflect.TypeOf(Out{}),
Type: reflect.TypeFor[Out](),
Anonymous: true,
}
)
Expand All @@ -120,7 +120,7 @@ type Annotation interface {
}

var (
_typeOfError = reflect.TypeOf((*error)(nil)).Elem()
_typeOfError = reflect.TypeFor[error]()
_nilError = reflect.Zero(_typeOfError)
)

Expand Down Expand Up @@ -661,8 +661,8 @@ func (la *lifecycleHookAnnotation) build(ann *annotated) (any, error) {
}

var (
_typeOfLifecycle = reflect.TypeOf((*Lifecycle)(nil)).Elem()
_typeOfContext = reflect.TypeOf((*context.Context)(nil)).Elem()
_typeOfLifecycle = reflect.TypeFor[Lifecycle]()
_typeOfContext = reflect.TypeFor[context.Context]()
)

// validateHookDeps validates the dependencies of a hook function and returns true if the dependencies are valid.
Expand Down Expand Up @@ -1299,7 +1299,7 @@ func (at *asAnnotation) apply(ann *annotated) error {
continue
}
t := reflect.TypeOf(typ)
if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Interface {
if t.Kind() != reflect.Pointer || t.Elem().Kind() != reflect.Interface {
return fmt.Errorf("fx.As: argument must be a pointer to an interface: got %v", t)
}
t = t.Elem()
Expand Down Expand Up @@ -1498,7 +1498,7 @@ func (fr *fromAnnotation) apply(ann *annotated) error {
return errors.New("fx.From: cannot annotate a variadic argument")
}
t := reflect.TypeOf(typ)
if t == nil || t.Kind() != reflect.Ptr {
if t == nil || t.Kind() != reflect.Pointer {
return fmt.Errorf("fx.From: argument must be a pointer to a type that implements some interface: got %v", t)
}
fr.types[i] = t.Elem()
Expand Down
1 change: 0 additions & 1 deletion app_unixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// THE SOFTWARE.

//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris

package fx

Expand Down
1 change: 0 additions & 1 deletion app_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// THE SOFTWARE.

//go:build (js && wasm) || (wasip1 && wasm)
// +build js,wasm wasip1,wasm

package fx

Expand Down
1 change: 0 additions & 1 deletion app_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// THE SOFTWARE.

//go:build windows
// +build windows

package fx

Expand Down
1 change: 0 additions & 1 deletion app_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// THE SOFTWARE.

//go:build windows
// +build windows

package fx_test

Expand Down
1 change: 0 additions & 1 deletion docs/ex/annotate/cast_bad.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// THE SOFTWARE.

//go:build ignore
// +build ignore

package annotate

Expand Down
2 changes: 1 addition & 1 deletion docs/ex/value-groups/consume/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package consume
import "go.uber.org/fx"

// Watcher watches for events.
type Watcher interface{}
type Watcher any

// ParamsModule is the module defined in this file.
var ParamsModule = fx.Options(
Expand Down
2 changes: 1 addition & 1 deletion docs/ex/value-groups/feed/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var ResultModule = fx.Options(
)

// Watcher watches for events.
type Watcher interface{}
type Watcher any

type watcher struct{}

Expand Down
6 changes: 3 additions & 3 deletions docs/src/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type App
func (app *App) Run()

type Option
func Provide(constructors ...interface{}) Option
func Invoke(funcs ...interface{}) Option
func Provide(constructors ...any) Option
func Invoke(funcs ...any) Option
```

Check the [API Reference](https://pkg.go.dev/go.uber.org/fx#Option)
Expand Down Expand Up @@ -82,7 +82,7 @@ it can only be used for non-interface values.
on runtime reflection to determine the type of the value.

Passing an interface value to `fx.Supply` is a lossy operation:
it loses the original interface type, only giving us `interface{}`,
it loses the original interface type, only giving us `any`,
at which point reflection will only reveal the concrete type of the value.

For example, consider:
Expand Down
6 changes: 3 additions & 3 deletions extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"unicode/utf8"
)

var _typeOfIn = reflect.TypeOf(In{})
var _typeOfIn = reflect.TypeFor[In]()

// Extract fills the given struct with values from the dependency injection
// container on application initialization. The target MUST be a pointer to a
Expand All @@ -37,7 +37,7 @@ var _typeOfIn = reflect.TypeOf(In{})
func Extract(target any) Option {
v := reflect.ValueOf(target)

if t := v.Type(); t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {
if t := v.Type(); t.Kind() != reflect.Pointer || t.Elem().Kind() != reflect.Struct {
return Error(fmt.Errorf("Extract expected a pointer to a struct, got a %v", t))
}

Expand Down Expand Up @@ -99,7 +99,7 @@ func Extract(target any) Option {
// https://github.com/golang/go/issues/21122

t := f.Type
if t.Kind() == reflect.Ptr {
if t.Kind() == reflect.Pointer {
t = t.Elem()
}

Expand Down
8 changes: 4 additions & 4 deletions internal/lifecycle/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ import (
// function type that cannot be converted to an underlying function type with
// a conventional conversion or type switch.
var (
_reflFunc = reflect.TypeOf(Func(nil))
_reflErrorFunc = reflect.TypeOf(ErrorFunc(nil))
_reflContextFunc = reflect.TypeOf(ContextFunc(nil))
_reflContextErrorFunc = reflect.TypeOf(ContextErrorFunc(nil))
_reflFunc = reflect.TypeFor[Func]()
_reflErrorFunc = reflect.TypeFor[ErrorFunc]()
_reflContextFunc = reflect.TypeFor[ContextFunc]()
_reflContextErrorFunc = reflect.TypeFor[ContextErrorFunc]()
)

// Discrete function signatures that are allowed as part of a [Callable].
Expand Down
4 changes: 2 additions & 2 deletions populate.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func Populate(targets ...any) Option {
fields := make([]reflect.StructField, len(targets)+1)
fields[0] = reflect.StructField{
Name: "In",
Type: reflect.TypeOf(In{}),
Type: reflect.TypeFor[In](),
Anonymous: true,
}
for i, t := range targets {
Expand All @@ -85,7 +85,7 @@ func Populate(targets ...any) Option {
default:
rt = reflect.TypeOf(t)
}
if rt.Kind() != reflect.Ptr {
if rt.Kind() != reflect.Pointer {
return Error(fmt.Errorf("failed to Populate: target %v is not a pointer type, got %T", i+1, t))
}
fields[i+1] = reflect.StructField{
Expand Down
2 changes: 1 addition & 1 deletion provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func runProvide(c container, p provide, opts ...dig.ProvideOption) error {
for i := 0; i < ft.NumOut(); i++ {
t := ft.Out(i)

if t == reflect.TypeOf(Annotated{}) {
if t == reflect.TypeFor[Annotated]() {
return fmt.Errorf(
"fx.Annotated should be passed to fx.Provide directly, "+
"it should not be returned by the constructor: "+
Expand Down
1 change: 0 additions & 1 deletion shutdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func TestDataRace(t *testing.T) {
// the signal received.
wg.Add(N)
for i := range N {
i := i
go func() {
defer wg.Done()
<-ready
Expand Down
4 changes: 2 additions & 2 deletions tools/analysis/passes/allfxevents/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var _filter = []ast.Node{
&ast.TypeAssertExpr{},
}

func run(pass *analysis.Pass) (interface{}, error) {
func run(pass *analysis.Pass) (any, error) {
fxeventPkg, ok := findPackage(pass.Pkg, "go.uber.org/fx/fxevent")
if !ok {
// If the package doesn't import fxevent, and itself isn't
Expand Down Expand Up @@ -261,7 +261,7 @@ func (ts *typeSet) Remove(t types.Type) (found bool) {

// Iterate iterates through the type set in an unspecified order.
func (ts *typeSet) Iterate(f func(types.Type)) {
ts.m.Iterate(func(t types.Type, _ interface{}) {
ts.m.Iterate(func(t types.Type, _ any) {
f(t)
})
}
Expand Down