Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft ancla helper edit #525

Closed
wants to merge 1 commit into from
Closed
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
37 changes: 7 additions & 30 deletions internal/anclaHelper/anclaHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,25 @@ import (
"go.uber.org/zap"
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type AnclaListenerIn struct {
type ServiceListenerIn struct{
fx.In
Measures ancla.Measures
Logger *zap.Logger
}
type AnclaServiceIn struct {
fx.In
Config ancla.Config
Listener ancla.ListenerConfig
Sink sink.Wrapper
//This is where we would need to add ancla.service struct
}

func InitializeAncla(lifecycle fx.Lifecycle) fx.Option {
return fx.Provide(
func(in AnclaListenerIn) ancla.ListenerConfig {
listener := ancla.ListenerConfig{
Measures: in.Measures,
Logger: in.Logger,
}
return listener
},
func(in AnclaServiceIn) int {
svc, err := ancla.NewService(in.Config, getLogger)
if err != nil {
fmt.Fprintf(os.Stderr, "Webhook service initialization error: %v\n", err)
return 1
}
return fx.Options(

//svc is the ancla.service struct that is returned when we call ancla.NewService(config, listener)
//can't have this in ancla as it requires the sink struct (implementing the ancla.Watch interface)
stopWatches, err := svc.StartListener(in.Listener, setLoggerInContext(), in.Sink)
if err != nil {
fmt.Fprintf(os.Stderr, "Webhook service start listener error: %v\n", err)
return 1
}
lifecycle.Append(fx.StopHook(stopWatches))
return 0
},
)
}

func getLogger(ctx context.Context) *zap.Logger {
logger := sallust.Get(ctx).With(zap.Time("ts", time.Now().UTC()), zap.Any("caller", zap.WithCaller(true)))
return logger
}
),
}

func setLoggerInContext() func(context.Context, *zap.Logger) context.Context {
Expand Down