func (c *Client) NewTenant(name, description string, enabled bool) (*Tenant, error) {
	b := bytes.NewBufferString(fmt.Sprintf(`{"tenant": {"name": "%s", "description": "%s", "enabled": %t}}`, name, description, enabled))
	response, _ := c.do("POST", c.authUrl+"/tenants", b)
	defer response.Body.Close()
	result, _ := ioutil.ReadAll(response.Body)
	if response.StatusCode > 399 {
		return nil, fmt.Errorf("Error while performing request: %d, %s", response.StatusCode, string(result))
	}
	var data map[string]map[string]interface{}
	_ = json.Unmarshal(result, &data)
	tenant := Tenant{
		Id:          data["tenant"]["id"].(string),
		Name:        data["tenant"]["name"].(string),
		Description: data["tenant"]["description"].(string),
	}
	return &tenant, nil
}
NewTenant creates a new tenant using the given name and description. The
third parameter is a flag that indicates if the tenant should be enabled or
not.
package keystone
import (
	"bytes"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"strings"
)
type ServiceCatalog struct {
	Endpoints []map[string]string
	Type      string
	Name      string
}
type Client struct {
	Token string
	Catalogs []ServiceCatalog
	authUrl string
}
type Tenant struct {
	Id          string
	Name        string
	Description string
}
type User struct {
	Id    string
	Name  string
	Email string
}
type Ec2 struct {
	Access string
	Secret string
}
func NewClient(username, password, tenantName, authUrl string) (*Client, error) {
	b := bytes.NewBufferString(fmt.Sprintf(`{"auth": {"passwordCredentials": {"username": "%s", "password":"%s"}, "tenantName": "%s"}}`, username, password, tenantName))
	response, err := http.Post(authUrl+"/tokens", "application/json", b)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()
	result, _ := ioutil.ReadAll(response.Body)
	var data map[string]map[string]interface{}
	err = json.Unmarshal(result, &data)
	if err != nil {
		return nil, err
	}
	if response.StatusCode > 399 {
		return nil, errors.New(data["error"]["title"].(string))
	}
	token := data["access"]["token"].(map[string]interface{})["id"].(string)
	client := Client{Token: token, authUrl: authUrl}
	catalogs, ok := data["access"]["serviceCatalog"].([]interface{})
	if !ok {
		return nil, errors.New("Error while accessing serviceCatalog key in returned json")
	}
	for _, c := range catalogs {
		catalog := c.(map[string]interface{})
		serviceCatalog := ServiceCatalog{
			Name: catalog["name"].(string),
			Type: catalog["type"].(string),
		}
		for _, e := range catalog["endpoints"].([]interface{}) {
			endpoint := map[string]string{}
			for k, v := range e.(map[string]interface{}) {
				endpoint[k] = v.(string)
			}
			serviceCatalog.Endpoints = append(serviceCatalog.Endpoints, endpoint)
		}
		client.Catalogs = append(client.Catalogs, serviceCatalog)
	}
	return &client, nil
}
func (c *Client) Endpoint(service, which string) string {
	var (
		endpoint string
		catalog  ServiceCatalog
	)
	for _, catalog = range c.Catalogs {
		if catalog.Type == service {
			break
		}
	}
	if catalog.Type == service {
		if !strings.Contains(which, "URL") {
			which += "URL"
		}
		endpoint = catalog.Endpoints[0][which]  
	}
	return endpoint
}
func (c *Client) do(method, urlStr string, body io.Reader) (*http.Response, error) {
	request, _ := http.NewRequest(method, urlStr, body)
	request.Header.Set("X-Auth-Token", c.Token)
	request.Header.Set("Connection", "close")  
	if body != nil {
		request.Header.Set("Content-Type", "application/json")
	}
	httpClient := &http.Client{}
	return httpClient.Do(request)
}