Files
htwkalender/backend/service/fetch/htmlDownloader.go
2023-11-30 00:00:38 +01:00

45 lines
799 B
Go

package fetch
import (
"fmt"
"io"
"net/http"
)
// getPlanHTML Get the HTML document from the specified URL
func GetHTML(url string) (string, error) {
// Send GET request
response, err := http.Get(url)
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 toUtf8(body), err
}
func toUtf8(iso88591Buf []byte) string {
buf := make([]rune, len(iso88591Buf))
for i, b := range iso88591Buf {
buf[i] = rune(b)
}
return string(buf)
}