Help to post response JSON

urlapi = https://yandex.ru/safety/check
site for check = likegodak.club
content type =json

Pls help, I can’t read response in structure YndexResponseModel
am i doing right?

now response always nil

func main() {

result := CheckYandex("likegodak.club")
if result != nil {
	fmt.Println(result.Info, result.Url)
}

}    
func CheckYandex(site string) (status *YndexResponseModel) {
type (
	Threatstr struct {
		Threat string
	}
	YndexResponseModel struct {
		Info []Threatstr
		Url  string
	}

)
var (
	apiurl    string = "https://yandex.ru/safety/check"
	cl               = &http.Client{Timeout: 15 * time.Second}
	strformat        = fmt.Sprintf(`{"url": "%s"}`, site)
	jsonStr          = []byte(strformat)
)

r, err := http.NewRequest("POST", apiurl, bytes.NewBuffer(jsonStr))
r.Header.Set("content-type", "application/json")
r.Close = true
resp, err := cl.Do(r)
checkerror(err)
defer resp.Body.Close()

err = json.NewDecoder(resp.Body).Decode(status)

return status

}

1 Like

Please keep the original question as it is and reply it as you want.

2 Likes

If you figured it out, please post the solution here :slight_smile: Maybe someone else has a similar problem and your solution can help them.

3 Likes