-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wire.go
35 lines (28 loc) · 860 Bytes
/
wire.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//go:build wireinject
package main
import (
"log/slog"
"time"
"github.com/google/wire"
"github.com/robfig/cron/v3"
"github.com/SkYNewZ/gh-stars-search-engine/internal/logging"
"github.com/SkYNewZ/gh-stars-search-engine/internal/slogx"
)
// setupScheduler is used by wire to inject the scheduler.
func setupScheduler(location string, logger *slog.Logger) (*cron.Cron, error) {
panic(wire.Build(
provideSchedulerLocation,
provideSchedulerOptions,
cron.New,
))
}
func provideSchedulerLocation(location string) (*time.Location, error) {
panic(wire.Build(time.LoadLocation))
}
func provideSchedulerOptions(loc *time.Location, logger *slog.Logger) []cron.Option {
schedulerLogger := logger.With(slogx.Component("scheduler"))
return []cron.Option{
cron.WithLocation(loc),
cron.WithLogger(logging.NewLoggerScheduler(schedulerLogger)),
}
}