1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package discourse
- import (
- "encoding/json"
- "fmt"
- "net/http"
- )
- type DashboardResponse struct {
- Dashboard Dashboard `json:"dashboard"`
- Errors []string `json:"errors"`
- ErrorType string `json:"error_type"`
- }
- type Dashboard struct {
- UpdatedAt string `json:"updated_at"`
- VersionCheck VersionCheck `json:"version_check"`
- }
- type VersionCheck struct {
- InstalledVersion string `json:"installed_version"`
- InstalledSha string `json:"installed_sha"`
- InstalledDescribe string `json:"installed_describe"`
- GitBranch string `json:"git_branch"`
- UpdatedAt string `json:"updated_at"`
- LatestVersion string `json:"latest_version"`
- CritialUpdates bool `json:"critical_updates"`
- MissingVersionsCount int `json:"missing_versions_count"`
- StaleData bool `json:"stale_data"`
- }
- // GetDashboard - Get a discourse admin dashboard
- func GetDashboard(config APIConfig) (Dashboard, error) {
- url := fmt.Sprintf("%s/admin/dashboard.json", config.Endpoint)
- req, _ := newGetRequest(config, url)
- client := getClient(rl)
- response, err := client.Do(req)
- if err != nil {
- return Dashboard{}, fmt.Errorf("Unable to connect to discourse server at %s -- %s", url, err)
- }
- if response.StatusCode == http.StatusOK || response.StatusCode == http.StatusForbidden {
- var result *Dashboard
- json.NewDecoder(response.Body).Decode(&result)
- return *result, nil
- }
- return Dashboard{}, fmt.Errorf("Unexpected response from discourse server at %s -- %s", url, response.Status)
- }
- // GetVersionCheck will retrieve the admin version check dat from discourse
- func GetVersionCheck(config APIConfig) (VersionCheck, error) {
- url := fmt.Sprintf("%s/admin/version_check.json", config.Endpoint)
- req, _ := newGetRequest(config, url)
- client := getClient(rl)
- response, err := client.Do(req)
- if err != nil {
- return VersionCheck{}, fmt.Errorf("Unable to connect to discourse server at %s -- %s", url, err)
- }
- if response.StatusCode == http.StatusOK || response.StatusCode == http.StatusForbidden {
- var result *VersionCheck
- json.NewDecoder(response.Body).Decode(&result)
- return *result, nil
- }
- return VersionCheck{}, fmt.Errorf("Unexpected response from discourse server at %s -- %s", url, response.Status)
- }
|