generated from pikachu0310/go-backend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (44 loc) · 1.09 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
51
52
53
package main
import (
"fmt"
"github.com/jmoiron/sqlx"
"github.com/joho/godotenv"
"github.com/traPtitech/BOT_GPT/internal/bot"
"github.com/traPtitech/BOT_GPT/internal/gpt"
"github.com/traPtitech/BOT_GPT/internal/handler"
"github.com/traPtitech/BOT_GPT/internal/migration"
"github.com/traPtitech/BOT_GPT/internal/pkg/config"
"github.com/traPtitech/BOT_GPT/internal/repository"
"log"
)
func main() {
err := godotenv.Load(".env")
if err != nil {
fmt.Printf(".env is not exist: %v", err)
}
// connect to database
db, err := sqlx.Connect("mysql", config.MySQL().FormatDSN())
if err != nil {
log.Fatal(err)
}
defer db.Close()
// migrate tables
if err := migration.MigrateTables(db.DB); err != nil {
log.Fatal(err)
}
// setup repository
repo := repository.New(db)
repository.InitDB(db)
// setup handler
h := handler.New(repo)
// initialize bot and gpt
bot.InitBot()
gpt.InitGPT()
// setup bot
traQBot := bot.GetBot()
traQBot.OnMessageCreated(h.MessageReceived())
traQBot.OnDirectMessageCreated(h.DirectMessageReceived())
if err := traQBot.Start(); err != nil {
panic(err)
}
}