add initial application structure with configuration, logging, and health check endpoints

This commit is contained in:
kever
2026-01-14 23:58:00 +08:00
commit fed727e593
31 changed files with 770 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package cron
import (
"context"
"time"
"github.com/robfig/cron/v3"
"go.uber.org/fx"
"go.uber.org/zap"
"epic-ent/internal/config"
)
func RegisterJobs(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) {
if !cfg.Cron.Enabled {
return
}
loc, err := time.LoadLocation(cfg.Cron.Timezone)
if err != nil {
logger.Warn("invalid timezone, fallback to Local", zap.Error(err))
loc = time.Local
}
c := cron.New(cron.WithLocation(loc))
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
c.Start()
logger.Info("cron started")
return nil
},
OnStop: func(ctx context.Context) error {
c.Stop()
logger.Info("cron stopped")
return nil
},
})
}