users.go 632 B

12345678910111213141516171819202122232425262728293031
  1. package discourse
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. )
  7. type UserResponse struct {
  8. User User `json:"user"`
  9. }
  10. type User struct {
  11. ID string `json:"id"`
  12. Username string `json:"username"`
  13. Moderator bool `json:"moderator"`
  14. Admin bool `json:"admin"`
  15. Groups []Group `json:"group"`
  16. }
  17. func GetUser(config ApiConfig, username string) {
  18. url := fmt.Sprintf("%s/users/%s.json?api_key=%s&api_username=%s", config.Endpoint, username, config.ApiKey, config.ApiUser)
  19. fmt.Println(url)
  20. response, _ := http.Get(url)
  21. var result User
  22. json.NewDecoder(response.Body).Decode(&result)
  23. fmt.Println(result)
  24. }