users.go 577 B

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