Mensa-CLI/internal/getMenu.go

38 lines
661 B
Go
Raw Normal View History

2024-09-18 10:08:11 +00:00
package internal
2024-09-18 17:08:47 +00:00
import (
"encoding/json"
"fmt"
"io"
"net/http"
"github.com/LeRoid-hub/Mensa-CLI/models"
)
2024-09-20 14:25:46 +00:00
func GetMenu(mensa string) (models.Mensa, error) {
http, err := http.Get("https://mensa.barfuss.email/mensa/" + mensa)
2024-09-18 17:08:47 +00:00
if err != nil {
return models.Mensa{}, err
}
defer http.Body.Close()
body, err := io.ReadAll(http.Body)
if err != nil {
return models.Mensa{}, err
}
var data models.Mensa
err = json.Unmarshal([]byte(body), &data)
if err != nil {
fmt.Println(err)
return models.Mensa{}, err
}
return data, nil
2024-09-18 10:08:11 +00:00
}
2024-09-20 14:25:46 +00:00
func GetSearchMenu(city string, mensa string) (models.Mensa, error) {
return GetMenu(city + "/" + mensa)
}