package main import ( "net/http" "github.com/LeRoid-hub/Mensa-API/blob/go/api/fetch.go" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.GET("/ping", ping) r.GET("/fetch", fetchRoute) r.Run("localhost:8080") } func fetchRoute(c *gin.Context) { url := c.Query("url") if url == "" { c.JSON(http.StatusBadRequest, gin.H{ "error": "url is required", }) return } resp, err := fetch.Fetch(url) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{ "error": err.Error(), }) return } defer resp.Body.Close() c.JSON(http.StatusOK, gin.H{ "status": resp.Status, }) } func ping(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "message": "pong", }) }