modernize the codebase
Run the modernize linter across the codebase. Change generated by running: ``` go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./... ``` Ref: https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize
This commit is contained in:
@@ -23,18 +23,18 @@ func main() {
|
||||
|
||||
// Configuration
|
||||
config.Load,
|
||||
|
||||
|
||||
// Database
|
||||
database.Connect,
|
||||
|
||||
|
||||
// Services
|
||||
services.NewPostService,
|
||||
services.NewImgKitHelper,
|
||||
|
||||
|
||||
// Auth
|
||||
auth.NewJwtTokenGenerator,
|
||||
auth.NewGiteaOauth2Token,
|
||||
|
||||
|
||||
// Handlers
|
||||
handlers.NewAdminDashboardHandler,
|
||||
handlers.NewApiEndpointHandler,
|
||||
@@ -44,7 +44,7 @@ func main() {
|
||||
fx.Invoke(
|
||||
// Start background tasks
|
||||
startBackgroundTasks,
|
||||
|
||||
|
||||
// Setup and start server
|
||||
server.SetupRouter,
|
||||
),
|
||||
@@ -62,49 +62,49 @@ func startBackgroundTasks(
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(context.Context) error {
|
||||
ticker := time.NewTicker(10 * time.Minute)
|
||||
|
||||
|
||||
runFetchPosts := func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
||||
posts, err := postService.GetPostsFromApi(ctx, cfg.Tag, cfg.Instance)
|
||||
if err != nil {
|
||||
logger.Error("Failed to fetch posts", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
existingPostIds := postService.GetExistingPostIds()
|
||||
existingAccountIds := postService.GetExistingAccountIds()
|
||||
newPosts := postService.GetNewPosts(existingPostIds, posts)
|
||||
newAccounts := postService.GetNewAccounts(existingAccountIds, newPosts)
|
||||
|
||||
|
||||
logger.Info("Fetched posts",
|
||||
zap.Int("total", len(posts)),
|
||||
zap.Int("existing", len(existingPostIds)),
|
||||
zap.Int("new", len(newPosts)),
|
||||
zap.Int("new_accounts", len(newAccounts)))
|
||||
|
||||
|
||||
if len(newAccounts) > 0 {
|
||||
count := postService.InsertNewAccounts(newAccounts)
|
||||
logger.Info("Inserted accounts", zap.Int("count", count))
|
||||
}
|
||||
|
||||
|
||||
if len(newPosts) > 0 {
|
||||
count := postService.InsertNewPosts(newPosts)
|
||||
logger.Info("Inserted posts", zap.Int("count", count))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Run initial fetch
|
||||
go runFetchPosts()
|
||||
|
||||
|
||||
// Start ticker
|
||||
go func() {
|
||||
for range ticker.C {
|
||||
runFetchPosts()
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
return nil
|
||||
},
|
||||
OnStop: func(context.Context) error {
|
||||
@@ -129,6 +129,6 @@ func NewFXLogger() *FXLogger {
|
||||
return &FXLogger{logger: logger}
|
||||
}
|
||||
|
||||
func (l *FXLogger) Printf(str string, args ...interface{}) {
|
||||
func (l *FXLogger) Printf(str string, args ...any) {
|
||||
l.logger.Sugar().Infof(str, args...)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user