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 { log *service.LoggerService // Логгер I *xsync.MapOf[*Bot] } func NewMap(Log *service.LoggerService) *Bots { return &Bots{ log: Log, I: xsync.NewMapOf[*Bot](), } } 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") } func (b *Bots) GetAll(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) }