|
@@ -6,26 +6,31 @@ import (
|
|
|
"net/http"
|
|
|
)
|
|
|
|
|
|
+// UserResponse - Structure of a discourse user api response
|
|
|
type UserResponse struct {
|
|
|
- User User `json:"user"`
|
|
|
+ User User `json:"user"`
|
|
|
+ Errors []string `json:"errors"`
|
|
|
+ ErrorType string `json:"error_type"`
|
|
|
}
|
|
|
|
|
|
+// User - A discoruse User
|
|
|
type User struct {
|
|
|
- ID string `json:"id"`
|
|
|
+ ID int `json:"id"`
|
|
|
Username string `json:"username"`
|
|
|
+ CanSendPM bool `json:"can_send_private_messages"`
|
|
|
Moderator bool `json:"moderator"`
|
|
|
Admin bool `json:"admin"`
|
|
|
- Groups []Group `json:"group"`
|
|
|
+ Groups []Group `json:"groups"`
|
|
|
}
|
|
|
|
|
|
-func GetUser(config ApiConfig, username string) {
|
|
|
+// GetUser - Get a discourse user
|
|
|
+func GetUser(config ApiConfig, username string) User {
|
|
|
url := fmt.Sprintf("%s/users/%s.json?api_key=%s&api_username=%s", config.Endpoint, username, config.ApiKey, config.ApiUser)
|
|
|
- fmt.Println(url)
|
|
|
|
|
|
response, _ := http.Get(url)
|
|
|
|
|
|
- var result User
|
|
|
+ var result *UserResponse
|
|
|
json.NewDecoder(response.Body).Decode(&result)
|
|
|
|
|
|
- fmt.Println(result)
|
|
|
+ return result.User
|
|
|
}
|