This commit is contained in:
Владимир Фёдоров 2023-08-13 21:06:28 +07:00
parent 1e3f5eb91d
commit bdc89bea14
5 changed files with 53 additions and 4 deletions

View File

@ -5,19 +5,28 @@ import (
"os"
"git.3crabs.ru/VLADIMIR/butler/internal/modules/messenger/telegram"
"git.3crabs.ru/VLADIMIR/butler/internal/modules/storage"
"git.3crabs.ru/VLADIMIR/butler/internal/modules/storage/postgres"
"git.3crabs.ru/VLADIMIR/butler/internal/services/bot"
"git.3crabs.ru/VLADIMIR/butler/internal/services/bot/bot_all"
"git.3crabs.ru/VLADIMIR/butler/internal/services/listener"
)
func main() {
args := os.Args[1:] // tg token
messengerTelegram, err := telegram.NewMessengerTelegram(args[0])
args := os.Args[1:]
tgToken := args[0]
messengerTelegram, err := telegram.NewMessengerTelegram(tgToken)
if err != nil {
panic(err)
}
var storage storage.IStorage // TODO: init
urlConnect := args[1]
storage, err := postgres.NewStoragePostgres(urlConnect)
if err != nil {
panic(err)
}
defer storage.Close()
listenerService := listener.NewListener(
messengerTelegram,
[]bot.IBot{

1
go.mod
View File

@ -8,6 +8,7 @@ require (
)
require (
github.com/lib/pq v1.10.9 // indirect
github.com/samber/lo v1.38.1 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
)

2
go.sum
View File

@ -1,5 +1,7 @@
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU=

View File

@ -12,4 +12,5 @@ type User struct {
type IStorage interface {
UpsertUser(ctx context.Context, user User) error
GetAllUsersByChatID(ctx context.Context, chatID string) ([]User, error)
Close()
}

View File

@ -0,0 +1,36 @@
package postgres
import (
"context"
"database/sql"
_ "github.com/lib/pq"
"git.3crabs.ru/VLADIMIR/butler/internal/modules/storage"
)
type storagePostgres struct {
db *sql.DB
}
func NewStoragePostgres(urlConnect string) (storage.IStorage, error) {
db, err := sql.Open("postgres", urlConnect)
if err != nil {
return nil, err
}
return &storagePostgres{db: db}, nil
}
func (s *storagePostgres) GetAllUsersByChatID(ctx context.Context, chatID string) ([]storage.User, error) {
// TODO: imptement
return nil, nil
}
func (s *storagePostgres) UpsertUser(ctx context.Context, user storage.User) error {
// TODO: imptement
return nil
}
func (s *storagePostgres) Close() {
s.db.Close()
}