2022-11-06 04:34:34 +09:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2023-06-06 20:25:00 +09:00
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
2022-11-06 04:34:34 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
func GetRequest(url string) gjson.Result {
|
2023-06-06 20:25:00 +09:00
|
|
|
r, err := http.NewRequest("GET", url, nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-11-06 04:34:34 +09:00
|
|
|
|
2023-06-06 20:25:00 +09:00
|
|
|
UserAgent, ok := os.LookupEnv("GITLIN_USER_AGENT")
|
|
|
|
if !ok {
|
|
|
|
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
|
|
|
|
}
|
|
|
|
r.Header.Set("Accept", "application/vnd.github.v3+json")
|
|
|
|
r.Header.Set("User-Agent", UserAgent)
|
2022-11-06 04:34:34 +09:00
|
|
|
|
2023-06-06 20:25:00 +09:00
|
|
|
client := &http.Client{}
|
|
|
|
res, err := client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-11-06 04:34:34 +09:00
|
|
|
|
2023-06-06 20:25:00 +09:00
|
|
|
defer res.Body.Close()
|
2022-11-06 04:34:34 +09:00
|
|
|
|
2023-06-06 20:25:00 +09:00
|
|
|
body, err := io.ReadAll(res.Body)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
jsonified := gjson.Parse(string(body))
|
2022-11-06 04:34:34 +09:00
|
|
|
|
2023-06-06 20:25:00 +09:00
|
|
|
return jsonified
|
2022-11-06 04:34:34 +09:00
|
|
|
}
|