Post-Migrator/services/wordpress/get-posts.go

32 lines
744 B
Go

package wordpress
import (
"encoding/json"
"federated.computer/wp-sync-slowtwitch/utilities"
)
type PostData struct {
Id int `json:"id"`
Link string `json:"link"`
Title struct {
Rendered string `json:"rendered"`
} `json:"title"`
Content struct {
Rendered string `json:"rendered"`
} `json:"content"`
AuthorId int `json:"author"`
Excerpt struct {
Rendered string `json:"rendered"`
} `json:"excerpt"`
FeaturedMediaId int `json:"featured_media"`
}
func GetPosts(baseUrl, user, pass string) []PostData {
url := baseUrl + "wp-json/wp/v2/posts?per_page=99"
body := utilities.GetHttpRequestToWordpress(url, user, pass)
var posts []PostData
err := json.Unmarshal(body, &posts)
utilities.CheckError(err)
return posts
}