-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (40 loc) · 1.33 KB
/
main.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"fmt"
"os"
"os/signal"
"sync"
"syscall"
"github.com/LemonNekoGH/make-it-a-quote-tg-bot/internal/config"
"github.com/LemonNekoGH/make-it-a-quote-tg-bot/internal/processor"
"github.com/LemonNekoGH/make-it-a-quote-tg-bot/internal/sentry"
"github.com/LemonNekoGH/make-it-a-quote-tg-bot/internal/telegram"
"github.com/LemonNekoGH/make-it-a-quote-tg-bot/pkg/logger"
"github.com/samber/do"
)
func main() {
// banner
fmt.Printf("=================\n")
fmt.Printf("MAKE IT A QUOTE\n")
fmt.Printf("Version: %s\n", config.Version)
fmt.Printf("Environment: %s\n", config.Env)
fmt.Printf("=================\n")
injector := do.New()
do.Provide(injector, logger.NewLoggerService)
do.Provide(injector, config.NewConfigService)
do.Provide(injector, sentry.NewSentryService)
do.MustInvoke[sentry.SentryService](injector) // 手动使依赖变得有用
do.Provide(injector, telegram.NewTelegramBotService)
do.Provide(injector, processor.NewProcessorsService)
// graceful shutdown
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
wg := sync.WaitGroup{}
wg.Add(1)
// start
processors := do.MustInvoke[processor.ProcessorsService](injector)
tg := do.MustInvoke[telegram.TelegramBotService](injector)
tg.RegisterCommand(processors.Commands())
go tg.Start(ctx, &wg)
wg.Wait()
}