add db
This commit is contained in:
parent
1e3f5eb91d
commit
bdc89bea14
|
@ -5,19 +5,28 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.3crabs.ru/VLADIMIR/butler/internal/modules/messenger/telegram"
|
"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"
|
||||||
"git.3crabs.ru/VLADIMIR/butler/internal/services/bot/bot_all"
|
"git.3crabs.ru/VLADIMIR/butler/internal/services/bot/bot_all"
|
||||||
"git.3crabs.ru/VLADIMIR/butler/internal/services/listener"
|
"git.3crabs.ru/VLADIMIR/butler/internal/services/listener"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
args := os.Args[1:] // tg token
|
args := os.Args[1:]
|
||||||
messengerTelegram, err := telegram.NewMessengerTelegram(args[0])
|
|
||||||
|
tgToken := args[0]
|
||||||
|
messengerTelegram, err := telegram.NewMessengerTelegram(tgToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
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(
|
listenerService := listener.NewListener(
|
||||||
messengerTelegram,
|
messengerTelegram,
|
||||||
[]bot.IBot{
|
[]bot.IBot{
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -8,6 +8,7 @@ require (
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/lib/pq v1.10.9 // indirect
|
||||||
github.com/samber/lo v1.38.1 // indirect
|
github.com/samber/lo v1.38.1 // indirect
|
||||||
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
|
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -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 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
|
||||||
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
|
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 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
|
||||||
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
|
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
|
||||||
go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU=
|
go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU=
|
||||||
|
|
|
@ -12,4 +12,5 @@ type User struct {
|
||||||
type IStorage interface {
|
type IStorage interface {
|
||||||
UpsertUser(ctx context.Context, user User) error
|
UpsertUser(ctx context.Context, user User) error
|
||||||
GetAllUsersByChatID(ctx context.Context, chatID string) ([]User, error)
|
GetAllUsersByChatID(ctx context.Context, chatID string) ([]User, error)
|
||||||
|
Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
Loading…
Reference in New Issue