func init() { defer PrintSpecReport() Describe("gets config", func() { It("gets default configs", func() { s := config.Config("iron_undefined") Expect(s.Host, ToEqual, "undefined-aws-us-east-1.iron.io") }) }) }
func (q *Queue) UnmarshalJSON(data []byte) error { var name struct { Name string `json:"name"` } err := json.Unmarshal(data, &name) q.Name = name.Name q.Settings = config.Config("iron_mq") // TODO could maybe cache this in config, map[$PWD]config, if $PWD changes, update config return err }
func main() { // Create your configuration for iron_worker // Find these value in credentials config := config.Config("iron_worker") config.ProjectId = "your_project_id" config.Token = "your_token" // Capture info for this task taskId := "52b45b17a31186632b00da4c" // Create your endpoint url for tasks url := api.Action(config, "tasks", taskId) log.Printf("Url: %s\n", url.URL.String()) // Post the request to Iron.io resp, err := url.Request("GET", nil) defer resp.Body.Close() if err != nil { log.Println(err) return } // Check the status code if resp.StatusCode != 200 { log.Printf("%v\n", resp) return } // Capture the response body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Println(err) return } // Unmarshall to struct task := &Task{} err = json.Unmarshal(body, task) if err != nil { log.Printf("%v\n", err) return } // Or you can Unmarshall to map results := map[string]interface{}{} err = json.Unmarshal(body, &results) if err != nil { log.Printf("%v\n", err) return } // Pretty print the response prettyPrint(task) }
func main() { // Create your configuration for iron_worker // Find these value in credentials config := config.Config("iron_worker") config.ProjectId = "your_project_id" config.Token = "your_token" // Create your endpoint url for tasks url := api.ActionEndpoint(config, "tasks") log.Printf("Url: %s\n", url.URL.String()) // Convert the payload to a slice of bytes postData := bytes.NewBufferString(payload) // Post the request to Iron.io resp, err := url.Request("POST", postData) defer resp.Body.Close() if err != nil { log.Println(err) return } // Capture the response body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Println(err) return } // Unmarshall to struct taskResponse := &TaskResponse{} err = json.Unmarshal(body, taskResponse) if err != nil { log.Printf("%v\n", err) return } // Or you can Unmarshall to map results := map[string]interface{}{} err = json.Unmarshal(body, &results) if err != nil { log.Printf("%v\n", err) return } // Pretty print the response prettyPrint(taskResponse) }
func main() { // Create your configuration for iron_worker // Find these value in credentials config := config.Config("iron_worker") config.ProjectId = "your_project_id" config.Token = "your_token" // Capture info for this task taskId := "52b45b17a31186632b00da4c" // Create your endpoint url for tasks url := api.Action(config, "tasks", taskId, "log") log.Printf("Url: %s\n", url.URL.String()) // Post the request to Iron.io resp, err := url.Request("GET", nil) defer resp.Body.Close() if err != nil { log.Println(err) return } // Check the status code if resp.StatusCode != 200 { log.Printf("%v\n", resp) return } // Capture the response body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Println(err) return } // Display the log log.Printf("\n%s\n", string(body)) }
func listQueues(prefix, prev string, perPage int) ([]Queue, error) { var out struct { Queues []Queue `json:"queues"` } url := api.Action(config.Config("iron_mq"), "queues") if prev != "" { url.QueryAdd("previous", "%v", prev) } if prefix != "" { url.QueryAdd("prefix", "%v", prefix) } if perPage != 0 { url.QueryAdd("per_page", "%d", perPage) } err := url.Req("GET", nil, &out) if err != nil { return nil, err } return out.Queues, nil }
func New() *Worker { return &Worker{Settings: config.Config("iron_worker")} }
// New uses the configuration specified in an iron.json file or environment variables // to return a Queue object capable of acquiring information about or modifying the queue // specified by queueName. func New(queueName string) Queue { return Queue{Settings: config.Config("iron_mq"), Name: queueName} }
// New returns a struct ready to make requests with. // The cacheName argument is used as namespace. func New(cacheName string) *Cache { return &Cache{Settings: config.Config("iron_cache"), Name: cacheName} }
// Like ListPage, but with an added filter. func FilterPage(prefix, prev string, perPage int) ([]Queue, error) { return ListQueues(config.Config("iron_mq"), prefix, prev, perPage) }
// Filter is like List, but will only return queues with the specified prefix. func Filter(prefix string) ([]Queue, error) { return ListQueues(config.Config("iron_mq"), prefix, "", 0) }
// List will get a listQueues of all queues for the configured project, paginated 30 at a time. // For paging or filtering, see ListPage and Filter. func List() ([]Queue, error) { return ListQueues(config.Config("iron_mq"), "", "", 0) }
// Like ListPage, but with an added filter. // Uses the default configuration settings. func FilterPage(prefix, prev string, perPage int) ([]Queue, error) { return FilterPageConfig(prefix, prev, perPage, config.Config("iron_mq")) }
// Filter is like List, but will only return queues with the specified prefix. // Uses the default configuration settings. func Filter(prefix string) ([]Queue, error) { return FilterConfig(prefix, config.Config("iron_mq")) }
// ListPage is like List, but will allow specifying a page length and pagination // To get the first page, let prev = "". // To get the second page, use the name of the last queue on the first page as "prev". // Uses the default configuration settings. func ListPage(prev string, perPage int) ([]Queue, error) { return ConfigListPage(prev, perPage, config.Config("iron_mq")) }
// List will get a listQueues of all queues for the configured project, paginated 30 at a time // For paging or filtering, see ListPage and Filter. // Uses the default configuration settings. func List() ([]Queue, error) { return ConfigList(config.Config("iron_mq")) }