remove http handlers

This commit is contained in:
Кобелев Андрей Андреевич 2022-06-08 10:30:13 +03:00
parent ff76b5842d
commit b23fbd1d8e
1 changed files with 0 additions and 55 deletions

55
map.go
View File

@ -1,12 +1,8 @@
package bot
import (
"strconv"
"git.belvedersky.ru/common/logger/service"
"github.com/gofiber/fiber/v2"
"github.com/puzpuzpuz/xsync"
"gopkg.in/telebot.v3"
)
type Bots struct {
@ -20,54 +16,3 @@ func NewMap(Log *service.LoggerService) *Bots {
I: xsync.NewMapOf[*Bot](),
}
}
// Get godoc
// @Summary Получение бота
// @Description Получение бота по username
// @ID bots/get
// @Tags Боты
// @Param name path string true "Username бота"
// @Router /bot/{name} [get]
// @Success 200 {object} telebot.User
func (b *Bots) Get(c *fiber.Ctx) error {
name := c.Params("name")
if name != "" {
b.log.Log.Println("Запрос на получение бота", name)
_b, ok := b.I.Load(name)
if !ok {
botId, err := strconv.Atoi(name)
if err != nil {
return err
}
b.I.Range(func(key string, bot *Bot) bool {
if bot.Self().ID == int64(botId) {
_b = bot
return false
}
return true
})
if _b == nil {
return c.Status(404).SendString("not found")
}
}
return c.JSON(_b.Self())
}
return c.Status(404).SendString("not found")
}
// List godoc
// @Summary Получение списка ботов
// @Description Получение списка ботов
// @ID bots/list
// @Tags Боты
// @Router /bot/list [get]
// @Success 200 {array} telebot.User
func (b *Bots) List(c *fiber.Ctx) error {
bots := []*telebot.User{}
b.I.Range(func(key string, value *Bot) bool {
bot := value
bots = append(bots, bot.Self())
return true
})
return c.JSON(bots)
}