41 lines
842 B
Go
41 lines
842 B
Go
|
package wordpress
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"federated.computer/wp-sync-slowtwitch/utilities"
|
||
|
"io"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
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 string) []PostData {
|
||
|
url := "posts?per_page=99"
|
||
|
req, err := http.Get(baseUrl + url)
|
||
|
utilities.CheckError(err)
|
||
|
|
||
|
defer utilities.CloseBodyAndCheckError(req.Body)
|
||
|
|
||
|
body, err := io.ReadAll(req.Body)
|
||
|
utilities.CheckError(err)
|
||
|
|
||
|
var posts []PostData
|
||
|
err = json.Unmarshal(body, &posts)
|
||
|
utilities.CheckError(err)
|
||
|
return posts
|
||
|
}
|