package handler import ( "log" "net/http" "strings" "sync/atomic" "time" "github.com/gin-gonic/gin" v1 "github.com/retailcrm/mg-transport-api-client-go/v1" "vk-webhook-flooder-mock/dto" ) var totalUserless uint32 = 0 func NewMessageHandler(c *gin.Context) { var snd v1.SendData if err := c.ShouldBindJSON(&snd); err != nil { c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errors": []string{err.Error()}}) return } if strings.HasPrefix(snd.Customer.Firstname, "User #") { total := atomic.AddUint32(&totalUserless, 1) log.Printf("MG NewMessageHandler: [%d] Beware! Message external_id=%s has placeholder user.", total, snd.Message.ExternalID) } c.JSON(http.StatusOK, dto.MessagesResponse{ MessageID: int(time.Now().UnixNano()), Time: time.Now(), }) }