Middleware

This commit is contained in:
2023-01-24 00:37:08 +03:00
parent b074189d31
commit 599584ea58
6 changed files with 49 additions and 19 deletions

24
bot.go
View File

@ -10,12 +10,21 @@ import (
)
type bot struct {
chatID int64
me *echo.User
echo.API
data StateData
lock sync.Mutex
state Runnable
chatID int64
me *echo.User
data StateData
lock sync.Mutex
state Runnable
handler UpdateHandler
}
func DefaultHandler(u *Update) error {
err := u.Bot.state.Call(u)
if err != nil {
u.LogError("", err, true)
}
return err
}
func (b *bot) Update(u *echo.Update) {
@ -30,8 +39,5 @@ func (b *bot) Update(u *echo.Update) {
b.lock.Lock()
defer b.lock.Unlock()
err := b.state.Call(upd)
if err != nil {
upd.LogError("", err, true)
}
b.handler(upd)
}