File tree 4 files changed +31
-8
lines changed
4 files changed +31
-8
lines changed Original file line number Diff line number Diff line change @@ -44,8 +44,6 @@ Libraries or functions that help to maintain and improve the application.
44
44
45
45
Databases and their functionalities.
46
46
47
- No business logic should be implemented here, just simple ` CRUD ` .
48
-
49
47
## /services
50
48
51
49
Services that application provides.
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ import (
13
13
"github.com/barahouei/clean-architecture-telegram-bot/handlers/bot"
14
14
"github.com/barahouei/clean-architecture-telegram-bot/models"
15
15
"github.com/barahouei/clean-architecture-telegram-bot/pkg/logger/zap"
16
+ "github.com/barahouei/clean-architecture-telegram-bot/repositories"
17
+ "github.com/barahouei/clean-architecture-telegram-bot/repositories/mongodb"
18
+ "github.com/barahouei/clean-architecture-telegram-bot/repositories/mysql"
16
19
"github.com/barahouei/clean-architecture-telegram-bot/repositories/postgres"
17
20
"github.com/urfave/cli/v2"
18
21
"go.uber.org/zap/zapcore"
@@ -64,12 +67,32 @@ func serve(c *cli.Context) error {
64
67
65
68
ctx := context .TODO ()
66
69
67
- db , err := postgres .New (ctx , cfg .Postgres , logger )
68
- if err != nil {
69
- logger .Error (err )
70
+ var db repositories.DB
70
71
71
- return err
72
+ switch cfg .App .Driver {
73
+ case "postgres" :
74
+ db , err = postgres .New (ctx , cfg .Postgres , logger )
75
+ if err != nil {
76
+ logger .Error (err )
77
+
78
+ return err
79
+ }
80
+ case "mysql" :
81
+ db , err = mysql .New (ctx , cfg .MySQL , logger )
82
+ if err != nil {
83
+ logger .Error (err )
84
+
85
+ return err
86
+ }
87
+ case "mongodb" :
88
+ db , err = mongodb .New (ctx , cfg .MongoDB , logger )
89
+ if err != nil {
90
+ logger .Error (err )
91
+
92
+ return err
93
+ }
72
94
}
95
+
73
96
defer db .Close (ctx )
74
97
75
98
bot := bot .New (db , logger )
Original file line number Diff line number Diff line change 1
1
BOT_NAME = cleanBot
2
2
BOT_APITOKEN = something
3
+ BOT_DB_DRIVER = postgres
3
4
4
5
BOT_POSTGRES_HOST = localhost
5
6
BOT_POSTGRES_PORT = 5432
Original file line number Diff line number Diff line change 17
17
}
18
18
19
19
App struct {
20
- Name string `env:"BOT_NAME,required"`
21
- Token string `env:"BOT_APITOKEN,required"`
20
+ Name string `env:"BOT_NAME,required"`
21
+ Token string `env:"BOT_APITOKEN,required"`
22
+ Driver string `env:"BOT_DB_DRIVER,required"`
22
23
}
23
24
24
25
Postgres struct {
You can’t perform that action at this time.
0 commit comments