about.go 835 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package discourse
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strings"
  6. )
  7. // AboutResponse - Structure of a discourse user api response
  8. type AboutResponse struct {
  9. About About `json:"about"`
  10. Errors []string `json:"errors"`
  11. ErrorType string `json:"error_type"`
  12. }
  13. // About data for the site
  14. type About struct {
  15. Version string `json:"version"`
  16. }
  17. // GetAbout - Get a discourse site about
  18. func GetAbout(config APIConfig) (About, error) {
  19. url := fmt.Sprintf("%s/about.json", config.Endpoint)
  20. req, _ := newGetRequest(config, url)
  21. client := getClient()
  22. response, _ := client.Do(req)
  23. var result *AboutResponse
  24. json.NewDecoder(response.Body).Decode(&result)
  25. if result.ErrorType != "" {
  26. return About{}, fmt.Errorf("Failed to get discourse user. Error: %s", strings.Join(result.Errors, "; "))
  27. }
  28. return result.About, nil
  29. }