1
0
mirror of https://github.com/mgerb/go-discord-bot synced 2026-01-11 17:42:48 +00:00

added logger

This commit is contained in:
2018-04-09 23:24:19 -05:00
parent 0fe7468506
commit 3e0cd3c948
10 changed files with 245 additions and 4 deletions

View File

@@ -0,0 +1,28 @@
package handlers
import (
"strconv"
"github.com/gin-gonic/gin"
"github.com/mgerb/go-discord-bot/server/db"
"github.com/mgerb/go-discord-bot/server/logger"
)
// GetLogs - get all logs
func GetLogs(c *gin.Context) {
page, err := strconv.Atoi(c.Query("page"))
if err != nil {
page = 0
}
messages := []logger.Message{}
err = db.Conn.Offset(page*100).Limit(100).Order("timestamp desc", true).Preload("User").Find(&messages).Error
if err != nil {
c.JSON(500, err)
return
}
c.JSON(200, messages)
}

View File

@@ -23,6 +23,7 @@ func getRouter() *gin.Engine {
api.GET("/ytdownloader", handlers.Downloader)
api.GET("/soundlist", handlers.SoundList)
api.GET("/cliplist", handlers.ClipList)
api.GET("/logs", handlers.GetLogs)
api.POST("/oauth", handlers.Oauth)
authorizedAPI := router.Group("/api")