mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2026-01-17 12:02:26 +01:00
feat:#39 added fetcher for SeminarGroups
This commit is contained in:
41
backend/service/fetch/v3/fetchClient.go
Normal file
41
backend/service/fetch/v3/fetchClient.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func requestJSON(url string, client *http.Client) (string, error) {
|
||||
// Send GET request with the given URL and special headers
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
fmt.Printf("Error occurred while creating the request: %s\n", err.Error())
|
||||
return "", err
|
||||
}
|
||||
// add header -H 'accept: application/ld+json'
|
||||
req.Header.Add("accept", "application/ld+json")
|
||||
|
||||
response, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error occurred while making the request: %s\n", err.Error())
|
||||
return "", err
|
||||
}
|
||||
defer func(Body io.ReadCloser) {
|
||||
err := Body.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}(response.Body)
|
||||
|
||||
// Read the response body
|
||||
body, err := io.ReadAll(response.Body)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error occurred while reading the response: %s\n", err.Error())
|
||||
return "", err
|
||||
}
|
||||
return string(body), err
|
||||
}
|
||||
Reference in New Issue
Block a user