0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-21 11:52:28 -05:00
safetwitch-backend/routes/api/users/users.go

30 lines
601 B
Go
Raw Normal View History

2023-05-18 10:17:08 -04:00
package users
import (
2023-05-20 16:30:12 -04:00
"safetwitch-backend/extractor"
"safetwitch-backend/extractor/twitch"
2023-05-20 16:30:12 -04:00
2023-05-18 10:17:08 -04:00
"github.com/gin-gonic/gin"
)
func Routes(route *gin.Engine) {
2023-05-26 10:17:55 -04:00
auth := route.Group("/api/users")
2023-05-18 10:17:08 -04:00
2023-05-20 16:30:12 -04:00
auth.GET("/:streamerName", func(context *gin.Context) {
data, err := twitch.GetStreamerInfo(context.Param("streamerName"))
if err != nil {
if err.Error() == "streamer not found" {
context.JSON(404, gin.H{
"status": "error",
"message": "streamer not found",
})
} else {
context.Error(err)
}
2023-05-22 18:11:42 -04:00
return
}
2023-05-22 18:11:42 -04:00
context.JSON(200, extractor.FormatMessage(data, true))
2023-05-18 10:17:08 -04:00
})
}