neko/internal/utils/request.go

23 lines
309 B
Go
Raw Normal View History

2021-03-11 01:15:18 +13:00
package utils
import (
"bytes"
2021-08-30 03:12:37 +12:00
"io"
2021-03-11 01:15:18 +13:00
"net/http"
)
func HttpRequestGET(url string) (string, error) {
rsp, err := http.Get(url)
if err != nil {
return "", err
}
defer rsp.Body.Close()
2021-08-30 03:12:37 +12:00
buf, err := io.ReadAll(rsp.Body)
2021-03-11 01:15:18 +13:00
if err != nil {
return "", err
}
return string(bytes.TrimSpace(buf)), nil
}