Browse Source

Update 'users.go'

thisnthat 5 years ago
parent
commit
ddfe4a6f54
1 changed files with 17 additions and 0 deletions
  1. 17 0
      users.go

+ 17 - 0
users.go

@@ -42,3 +42,20 @@ func GetUser(config APIConfig, username string) (User, error) {
 
 	return result.User, nil
 }
+
+func getUserByID(config APIConfig, userID int) (User, error) {
+	url := fmt.Sprintf("%s/admin/users/%d.json", config.Endpoint, userID)
+
+	req, _ := newGetRequest(config, url)
+	client := getClient()
+	response, _ := client.Do(req)
+
+	var result *UserResponse
+	json.NewDecoder(response.Body).Decode(&result)
+
+	if result.ErrorType != "" {
+		return User{}, fmt.Errorf("Failed to get discourse user. Error: %s", strings.Join(result.Errors, "; "))
+	}
+
+	return result.User, nil
+}