nguyenvanduocit
3/24/2018 - 4:07 PM

GetPage.go

func (converter *Converter)GetPage(page int)(*ApiResponse, error){
	url := "https://public-api.wordpress.com/rest/v1.1/sites/" + converter.WordPressDomain + "/posts/?number=100&page=" + strconv.Itoa(page) + "&order=ASC"
	httpClient := &http.Client{}
	response, err := httpClient.Get(url)
	if err != nil {
		return nil, err
	}
	defer response.Body.Close()
	var responseData ApiResponse
	err = json.NewDecoder(response.Body).Decode(&responseData)
	if err != nil {
		return nil, err
	}
	return &responseData, nil
}