mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2025-01-09 14:20:15 -05:00
28 lines
533 B
Go
28 lines
533 B
Go
|
package search
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
|
||
|
"safetwitch-backend/extractor"
|
||
|
"safetwitch-backend/extractor/twitch"
|
||
|
)
|
||
|
|
||
|
func Routes(route *gin.Engine) {
|
||
|
auth := route.Group("/api/search")
|
||
|
|
||
|
auth.GET("/", func(context *gin.Context) {
|
||
|
query := context.Query("query")
|
||
|
if query == "" {
|
||
|
context.JSON(400, extractor.FormatMessage("Missing query", false))
|
||
|
}
|
||
|
|
||
|
data, err := twitch.GetSearchResult(query)
|
||
|
if err != nil {
|
||
|
context.Error(err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
context.JSON(200, extractor.FormatMessage(data, true))
|
||
|
})
|
||
|
}
|