Post-Migrator/services/wordpress/get-user.go
2024-05-07 19:23:21 -06:00

28 lines
600 B
Go

package wordpress
import (
"encoding/json"
"federated.computer/wp-sync-slowtwitch/utilities"
"net/url"
)
type UserData struct {
Id int `json:"id"`
Name string `json:"name"`
}
func GetUser(baseUrl, name, user, pass string) (UserData, bool) {
endpoint := baseUrl + "users?search=" + url.QueryEscape(name)
body := utilities.GetHttpRequestToWordpress(endpoint, user, pass)
var userData []UserData
err := json.Unmarshal(body, &userData)
if err == nil {
for _, userData := range userData {
if userData.Name == name {
return userData, true
}
}
}
return UserData{}, false
}