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

32 lines
730 B
Go
Raw Normal View History

2024-05-07 22:03:15 +00:00
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 + "posts?per_page=99"
body := utilities.GetHttpRequestToWordpress(url, user, pass)
2024-05-07 22:03:15 +00:00
var posts []PostData
err := json.Unmarshal(body, &posts)
2024-05-07 22:03:15 +00:00
utilities.CheckError(err)
return posts
}