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

28 lines
606 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"
"net/url"
)
type UserData struct {
2024-05-08 00:52:47 +00:00
Id int `json:"id"`
Name string `json:"name"`
2024-05-07 22:03:15 +00:00
}
2024-05-08 00:52:47 +00:00
func GetUser(baseUrl, name, user, pass string) (UserData, bool) {
endpoint := baseUrl + "wp/v2/users?search=" + url.QueryEscape(name)
2024-05-07 22:03:15 +00:00
body := utilities.GetHttpRequestToWordpress(endpoint, user, pass)
var userData []UserData
err := json.Unmarshal(body, &userData)
if err == nil {
for _, userData := range userData {
2024-05-08 00:52:47 +00:00
if userData.Name == name {
2024-05-07 22:03:15 +00:00
return userData, true
}
}
}
return UserData{}, false
}