Explorar el Código

Update 'users.go'

thisnthat hace 5 años
padre
commit
ddfe4a6f54
Se han modificado 1 ficheros con 17 adiciones y 0 borrados
  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
+}