mirror of
https://github.com/hanzo-fi/go-libs.git
synced 2026-10-30 20:53:44 +00:00
* refactor: move all packages under pkg/ for v5 Move all 13 top-level Go packages into pkg/ for a cleaner repository structure. All internal import paths updated from github.com/formancehq/go-libs/v5/<pkg> to github.com/formancehq/go-libs/v5/pkg/<pkg>. Also includes cleanup: - Fix .golangci.yml stale v4 CircuitBreaker path - Replace deprecated str.Contains with stdlib slices.Contains - Update TODO(v4) markers to TODO - Delete stale coverage.txt - Fix pgtesting timeout not being propagated to docker pool - Update docs/ARCHITECTURE.md to reflect new structure Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: remove compatibility aliases, unused params, and stub files - Remove unused type aliases (Authenticator, KeySet) from authnfx - Remove unused `debug` parameter from S3ModuleFromFlags - Delete comment-only stub files in messaging/publish/circuit/ Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: rename cli.go to flags.go for consistency Standardize naming across all packages: cli.go -> flags.go since these files all serve the same purpose (flag definitions). Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: rename * chore(deps): update all dependencies Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: resolve package name mismatches in generated mocks Generated mock files had stale package names from before the pkg/ move, causing import cycles and build failures with --build-tags it. Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
94 lines
1.6 KiB
Go
94 lines
1.6 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type contextKey string
|
|
|
|
const (
|
|
lifecycleContextKey contextKey = "ready"
|
|
debugKey contextKey = "debug"
|
|
)
|
|
|
|
var closedChan = make(chan struct{})
|
|
|
|
func init() {
|
|
close(closedChan)
|
|
}
|
|
|
|
type lifecycle struct {
|
|
ready chan struct{}
|
|
stopped chan struct{}
|
|
}
|
|
|
|
func newLifecycle() *lifecycle {
|
|
return &lifecycle{
|
|
ready: make(chan struct{}),
|
|
stopped: make(chan struct{}),
|
|
}
|
|
}
|
|
|
|
func contextWithLifecycle(ctx context.Context, lc *lifecycle) context.Context {
|
|
return context.WithValue(ctx, lifecycleContextKey, lc)
|
|
}
|
|
|
|
func lifecycleFromContext(ctx context.Context) *lifecycle {
|
|
lc := ctx.Value(lifecycleContextKey)
|
|
if lc == nil {
|
|
return nil
|
|
}
|
|
return lc.(*lifecycle)
|
|
}
|
|
|
|
func ContextWithLifecycle(ctx context.Context) context.Context {
|
|
return context.WithValue(ctx, lifecycleContextKey, newLifecycle())
|
|
}
|
|
|
|
func ContextWithDebug(ctx context.Context) context.Context {
|
|
return context.WithValue(ctx, debugKey, true)
|
|
}
|
|
|
|
func IsDebug(cmd *cobra.Command) bool {
|
|
ret, err := cmd.Flags().GetBool(DebugFlag)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return ret
|
|
}
|
|
|
|
func markAsAppReady(ctx context.Context) {
|
|
lc := lifecycleFromContext(ctx)
|
|
if lc == nil {
|
|
return
|
|
}
|
|
close(lc.ready)
|
|
}
|
|
|
|
func markAsAppStopped(ctx context.Context) {
|
|
lc := lifecycleFromContext(ctx)
|
|
if lc == nil {
|
|
return
|
|
}
|
|
close(lc.stopped)
|
|
}
|
|
|
|
func Ready(ctx context.Context) chan struct{} {
|
|
lc := lifecycleFromContext(ctx)
|
|
if lc == nil {
|
|
return closedChan
|
|
}
|
|
return lc.ready
|
|
}
|
|
|
|
func Stopped(ctx context.Context) chan struct{} {
|
|
lc := lifecycleFromContext(ctx)
|
|
if lc == nil {
|
|
return closedChan
|
|
}
|
|
|
|
return lc.stopped
|
|
}
|