Skip to content

Commit 9a575fb

Browse files
authored
Merge branch 'master' into dependabot/github_actions/codecov/codecov-action-5
2 parents 638a41e + ca61c3d commit 9a575fb

File tree

10 files changed

+35
-31
lines changed

10 files changed

+35
-31
lines changed

app.go

+14-16
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ type App struct {
304304

305305
container *dig.Container
306306
root *module
307-
modules []*module
308307

309308
// Timeouts used
310309
startTimeout time.Duration
@@ -446,7 +445,6 @@ func New(opts ...Option) *App {
446445
log: logger,
447446
trace: []string{fxreflect.CallerStack(1, 2)[0].String()},
448447
}
449-
app.modules = append(app.modules, app.root)
450448

451449
for _, opt := range opts {
452450
opt.apply(app.root)
@@ -475,10 +473,7 @@ func New(opts ...Option) *App {
475473
}
476474

477475
app.container = dig.New(containerOptions...)
478-
479-
for _, m := range app.modules {
480-
m.build(app, app.container)
481-
}
476+
app.root.build(app, app.container)
482477

483478
// Provide Fx types first to increase the chance a custom logger
484479
// can be successfully built in the face of unrelated DI failure.
@@ -490,31 +485,26 @@ func New(opts ...Option) *App {
490485
})
491486
app.root.provide(provide{Target: app.shutdowner, Stack: frames})
492487
app.root.provide(provide{Target: app.dotGraph, Stack: frames})
488+
app.root.provideAll()
493489

494-
for _, m := range app.modules {
495-
m.provideAll()
496-
}
497-
498-
// Run decorators before executing any Invokes -- including the one
499-
// inside constructCustomLogger.
490+
// Run decorators before executing any Invokes
491+
// (including the ones inside installAllEventLoggers).
500492
app.err = multierr.Append(app.err, app.root.decorateAll())
501493

502494
// If you are thinking about returning here after provides: do not (just yet)!
503495
// If a custom logger was being used, we're still buffering messages.
504496
// We'll want to flush them to the logger.
505497

506498
// custom app logger will be initialized by the root module.
507-
for _, m := range app.modules {
508-
m.constructAllCustomLoggers()
509-
}
499+
app.root.installAllEventLoggers()
510500

511501
// This error might have come from the provide loop above. We've
512502
// already flushed to the custom logger, so we can return.
513503
if app.err != nil {
514504
return app
515505
}
516506

517-
if err := app.root.executeInvokes(); err != nil {
507+
if err := app.root.invokeAll(); err != nil {
518508
app.err = err
519509

520510
if dig.CanVisualizeError(err) {
@@ -595,6 +585,14 @@ func (app *App) exit(code int) {
595585
// All of Run's functionality is implemented in terms of the exported
596586
// Start, Done, and Stop methods. Applications with more specialized needs
597587
// can use those methods directly instead of relying on Run.
588+
//
589+
// After the application has started,
590+
// it can be shut down by sending a signal or calling [Shutdowner.Shutdown].
591+
// On successful shutdown, whether initiated by a signal or by the user,
592+
// Run will return to the caller, allowing it to exit cleanly.
593+
// Run will exit with a non-zero status code
594+
// if startup or shutdown operations fail,
595+
// or if the [Shutdowner] supplied a non-zero exit code.
598596
func (app *App) Run() {
599597
// Historically, we do not os.Exit(0) even though most applications
600598
// cede control to Fx with they call app.Run. To avoid a breaking

docs/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module go.uber.org/fx/docs
22

3-
go 1.20
3+
go 1.22
44

55
require (
66
github.com/stretchr/testify v1.8.1

docs/go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
1313
go.uber.org/dig v1.18.0 h1:imUL1UiY0Mg4bqbFfsRQO5G4CGRBec/ZujWTvSVp3pw=
1414
go.uber.org/dig v1.18.0/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
1515
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
16+
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
1617
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
1718
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
1819
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=

docs/src/parameter-objects.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Parameter Objects
22

3-
A parameter object is an objects with the sole purpose of carrying parameters
3+
A parameter object is an object with the sole purpose of carrying parameters
44
for a specific function or method.
55

66
The object is typically defined exclusively for that function,

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module go.uber.org/fx
22

3-
go 1.20
3+
go 1.22
44

55
require (
66
github.com/stretchr/testify v1.8.1

go.sum

+5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
22
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
5+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
56
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
7+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
68
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
79
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
810
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -21,11 +23,14 @@ go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8
2123
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
2224
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
2325
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
26+
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
2427
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
2528
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2629
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
30+
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
2731
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2832
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
33+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2934
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3035
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
3136
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/e2e/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module go.uber.org/fx/internal/e2e
22

3-
go 1.20
3+
go 1.22
44

55
require (
66
github.com/stretchr/testify v1.8.2

internal/e2e/go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
1313
go.uber.org/dig v1.18.0 h1:imUL1UiY0Mg4bqbFfsRQO5G4CGRBec/ZujWTvSVp3pw=
1414
go.uber.org/dig v1.18.0/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
1515
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
16+
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
1617
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
1718
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
1819
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=

lifecycle.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type Hook struct {
5353
// StartHook returns a new Hook with start as its [Hook.OnStart] function,
5454
// wrapping its signature as needed. For example, given the following function:
5555
//
56-
// func myhook() {
56+
// func myfunc() {
5757
// fmt.Println("hook called")
5858
// }
5959
//
@@ -86,7 +86,7 @@ func StartHook[T HookFunc](start T) Hook {
8686
// StopHook returns a new Hook with stop as its [Hook.OnStop] function,
8787
// wrapping its signature as needed. For example, given the following function:
8888
//
89-
// func myhook() {
89+
// func myfunc() {
9090
// fmt.Println("hook called")
9191
// }
9292
//

module.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ func (m *module) supply(p provide) {
253253
}
254254

255255
// Constructs custom loggers for all modules in the tree
256-
func (m *module) constructAllCustomLoggers() {
256+
func (m *module) installAllEventLoggers() {
257257
if m.logConstructor != nil {
258258
if buffer, ok := m.log.(*logBuffer); ok {
259259
// default to parent's logger if custom logger constructor fails
260-
if err := m.constructCustomLogger(buffer); err != nil {
260+
if err := m.installEventLogger(buffer); err != nil {
261261
m.app.err = multierr.Append(m.app.err, err)
262262
m.log = m.fallbackLogger
263263
buffer.Connect(m.log)
@@ -269,12 +269,11 @@ func (m *module) constructAllCustomLoggers() {
269269
}
270270

271271
for _, mod := range m.modules {
272-
mod.constructAllCustomLoggers()
272+
mod.installAllEventLoggers()
273273
}
274274
}
275275

276-
// Mirroring the behavior of app.constructCustomLogger
277-
func (m *module) constructCustomLogger(buffer *logBuffer) (err error) {
276+
func (m *module) installEventLogger(buffer *logBuffer) (err error) {
278277
p := m.logConstructor
279278
fname := fxreflect.FuncName(p.Target)
280279
defer func() {
@@ -297,23 +296,23 @@ func (m *module) constructCustomLogger(buffer *logBuffer) (err error) {
297296
})
298297
}
299298

300-
func (m *module) executeInvokes() error {
299+
func (m *module) invokeAll() error {
301300
for _, m := range m.modules {
302-
if err := m.executeInvokes(); err != nil {
301+
if err := m.invokeAll(); err != nil {
303302
return err
304303
}
305304
}
306305

307306
for _, invoke := range m.invokes {
308-
if err := m.executeInvoke(invoke); err != nil {
307+
if err := m.invoke(invoke); err != nil {
309308
return err
310309
}
311310
}
312311

313312
return nil
314313
}
315314

316-
func (m *module) executeInvoke(i invoke) (err error) {
315+
func (m *module) invoke(i invoke) (err error) {
317316
fnName := fxreflect.FuncName(i.Target)
318317
m.log.LogEvent(&fxevent.Invoking{
319318
FunctionName: fnName,

0 commit comments

Comments
 (0)