gitlin/utils/getrequest.go
Arya Kiran 11def08969
fix organization info
I dont know why it happened but i fixed it
2023-02-14 15:22:53 +05:30

39 行
731 B
Go

package utils
import (
"github.com/tidwall/gjson"
"io"
"net/http"
"os"
)
func GetRequest(url string) gjson.Result {
r, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(err)
}
UserAgent, ok := os.LookupEnv("GOTHUB_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)
client := &http.Client{}
res, err := client.Do(r)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
jsonified := gjson.Parse(string(body))
return jsonified
}