🗃️ Finish database selection connection

This commit is contained in:
Alphyron 2020-04-11 23:35:40 +02:00
parent 18878de12c
commit a08defa167
2 changed files with 23 additions and 2 deletions

13
main.go
View File

@ -2,6 +2,8 @@ package main
import ( import (
"git.dragon-labs.de/alphyron/group_helper/config" "git.dragon-labs.de/alphyron/group_helper/config"
"git.dragon-labs.de/alphyron/group_helper/logic"
"git.dragon-labs.de/alphyron/group_helper/repository"
"log" "log"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
@ -32,4 +34,15 @@ func main() {
bot.Debug = tgConfig.TelegramDebug bot.Debug = tgConfig.TelegramDebug
log.Printf("Authorized on account %s", bot.Self.UserName) log.Printf("Authorized on account %s", bot.Self.UserName)
groupHelperRepo, err := repository.NewUserHelperRepository()
if err != nil {
log.Println("Problem while connection to the Database")
log.Fatal(err)
}
/* groupHelperService := */
logic.NewGroupHelperService(groupHelperRepo)
} }

View File

@ -4,14 +4,22 @@ import (
"errors" "errors"
"git.dragon-labs.de/alphyron/group_helper/config" "git.dragon-labs.de/alphyron/group_helper/config"
"git.dragon-labs.de/alphyron/group_helper/logic" "git.dragon-labs.de/alphyron/group_helper/logic"
"git.dragon-labs.de/alphyron/group_helper/repository/sql"
) )
func NewUserHelperRepository() (*logic.GroupHelperRepository, error) { func NewUserHelperRepository() (logic.GroupHelperRepository, error) {
databaseConfig := config.DatabaseConfig{} databaseConfig := config.DatabaseConfig{}
_ = databaseConfig.LoadConfig() _ = databaseConfig.LoadConfig()
switch databaseConfig.DatabaseType { switch databaseConfig.DatabaseType {
case "mysql":
return sql.NewGroupHelperRepository(&databaseConfig)
case "postgres":
return sql.NewGroupHelperRepository(&databaseConfig)
case "sqlite3":
return sql.NewGroupHelperRepository(&databaseConfig)
case "mssql":
return sql.NewGroupHelperRepository(&databaseConfig)
} }
return nil, errors.New("cannot support given database type (" + databaseConfig.DatabaseType + ")") return nil, errors.New("cannot support given database type (" + databaseConfig.DatabaseType + ")")