package discourse import ( "encoding/json" "fmt" "net/http" ) // UserResponse - Structure of a discourse user api response// UserResponse - Structure of a discourse user api response type UserResponse struct { User User `json:"user"` Errors []string `json:"errors"` ErrorType string `json:"error_type"` } // User - A discoruse User type User struct { ID int `json:"id" schema:"external_id"` Username string `json:"username"` CanSendPM bool `json:"can_send_private_messages"` Moderator bool `json:"moderator"` Admin bool `json:"admin"` Groups []Group `json:"groups"` GroupStr string `schema:"groups"` } // GetUser - Get a discourse user func GetUser(config APIConfig, username string) User { url := fmt.Sprintf("%s/users/%s.json?api_key=%s&api_username=%s", config.Endpoint, username, config.APIKey, config.APIUsername) response, _ := http.Get(url) var result *UserResponse json.NewDecoder(response.Body).Decode(&result) return result.User }