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

34 lines
742 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 {
Id int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
func GetUser(baseUrl, username, user, pass string) (UserData, bool) {
endpoint := baseUrl + "/users?search=" + url.QueryEscape(username)
body := utilities.GetHttpRequestToWordpress(endpoint, user, pass)
var userData []UserData
err := json.Unmarshal(body, &userData)
if err == nil {
for _, userData := range userData {
if userData.Username == username {
return userData, true
}
}
}
return UserData{}, false
}