28 lines
614 B
Go
28 lines
614 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 + "wp-json/wp/v2/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
|
|
}
|