mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
* chore: apply go fix modernizers from Go 1.26
automated refactoring: interface{} to any, slices.Contains,
and other idiomatic updates.
* feat(ci): add `go fix` check to Go analysis workflow
ensures Go 1.26 modernizers are applied, fails CI if `go fix ./...`
produces any changes (similar to existing `go fmt` enforcement)
57 lines
1.0 KiB
Go
57 lines
1.0 KiB
Go
package node
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
type lcStartStop struct {
|
|
fx.In
|
|
|
|
LC fx.Lifecycle
|
|
}
|
|
|
|
// Append wraps a function into a fx.Hook and appends it to the fx.Lifecycle.
|
|
func (lcss *lcStartStop) Append(f func() func()) {
|
|
// Hooks are guaranteed to run in sequence. If a hook fails to start, its
|
|
// OnStop won't be executed.
|
|
var stopFunc func()
|
|
|
|
lcss.LC.Append(fx.Hook{
|
|
OnStart: func(ctx context.Context) error {
|
|
if ctx.Err() != nil {
|
|
return nil
|
|
}
|
|
stopFunc = f()
|
|
return nil
|
|
},
|
|
OnStop: func(ctx context.Context) error {
|
|
if ctx.Err() != nil {
|
|
return nil
|
|
}
|
|
if stopFunc == nil { // Theoretically this shouldn't ever happen
|
|
return errors.New("lcStatStop: stopFunc was nil")
|
|
}
|
|
stopFunc()
|
|
return nil
|
|
},
|
|
})
|
|
}
|
|
|
|
func maybeProvide(opt any, enable bool) fx.Option {
|
|
if enable {
|
|
return fx.Provide(opt)
|
|
}
|
|
return fx.Options()
|
|
}
|
|
|
|
// nolint unused
|
|
func maybeInvoke(opt any, enable bool) fx.Option {
|
|
if enable {
|
|
return fx.Invoke(opt)
|
|
}
|
|
return fx.Options()
|
|
}
|