Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow specifying cloud when creating client

Closes #3
  • Loading branch information...
commit e49c57019a6553c5c314fbd74ebb4182deb8e348 1 parent 68eb580
@edsrzf edsrzf authored
Showing with 22 additions and 7 deletions.
  1. +1 −1  README.md
  2. +15 −0 cloud.go
  3. +5 −5 ironmq.go
  4. +1 −1  ironmq_test.go
View
2  README.md
@@ -14,7 +14,7 @@ The Basics
==========
**Initialize** a client and get a queue object:
- client := ironmq.NewClient("my project", "my token")
+ client := ironmq.NewClient("my project", "my token", ironmq.IronAWSUSEast)
queue := client.Queue("my_queue")
**Push** a message on the queue:
View
15 cloud.go
@@ -0,0 +1,15 @@
+package ironmq
+
+type Cloud struct {
+ scheme string
+ host string
+}
+
+func NewCloud(scheme, host string) *Cloud {
+ return &Cloud{scheme, host}
+}
+
+var (
+ IronAWSUSEast = NewCloud("https", "mq-aws-us-east-1.iron.io")
+ IronRackspaceDFW = NewCloud("https", "mq-rackspace-dfw.iron.io")
+)
View
10 ironmq.go
@@ -13,14 +13,15 @@ import (
// A Client contains an Iron.io project ID and a token for authentication.
type Client struct {
Debug bool
+ cloud *Cloud
projectId string
token string
}
// NewClient returns a new Client using the given project ID and token.
// The network is not used during this call.
-func NewClient(projectId, token string) *Client {
- return &Client{projectId: projectId, token: token}
+func NewClient(projectId, token string, cloud *Cloud) *Client {
+ return &Client{projectId: projectId, token: token, cloud: cloud}
}
type Error struct {
@@ -33,10 +34,9 @@ var EmptyQueue = errors.New("queue is empty")
func (e *Error) Error() string { return fmt.Sprintf("Status %d: %s", e.Status, e.Msg) }
func (c *Client) req(method, endpoint string, body []byte, data interface{}) error {
- const host = "mq-aws-us-east-1.iron.io"
const apiVersion = "1"
- url := path.Join(host, apiVersion, "projects", c.projectId, endpoint)
- url = "http://" + url + "?oauth=" + c.token
+ url := path.Join(c.cloud.host, apiVersion, "projects", c.projectId, endpoint)
+ url = c.cloud.scheme + "://" + url + "?oauth=" + c.token
req, err := http.NewRequest(method, url, bytes.NewBuffer(body))
if err != nil {
return err
View
2  ironmq_test.go
@@ -15,7 +15,7 @@ func TestFunctionality(t *testing.T) {
t.Fatalf("IRONIO_TOKEN environment variable not set")
}
- client := NewClient(projectId, token)
+ client := NewClient(projectId, token, IronAWSUSEast)
queue := client.Queue("test-queue")
// clear out the queue

3 comments on commit e49c570

@treeder
Owner

Probably want a port for those clouds if we also have scheme?

@edsrzf
Collaborator

Port is included in the host. If you want to specify a port, say, for example, "mq-aws-us-east-1.iron.io:8080"

@treeder
Owner
Please sign in to comment.
Something went wrong with that request. Please try again.