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 code codeId := "522d160a91c530531f6f528d" // Create your endpoint url for tasks url := api.Action(config, "codes", codeId) 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 code := &Code{} err = json.Unmarshal(body, code) if err != nil { log.Printf("%v\n", err) return } // 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(code) }
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 (c *Cache) caches(suffix ...string) *api.URL { return api.Action(c.Settings, "caches", suffix...) }
func (q Queue) queues(s ...string) *api.URL { return api.Action(q.Settings, "queues", s...) }
func (w *Worker) schedules(s ...string) *api.URL { return api.Action(w.Settings, "schedules", s...) }
func (w *Worker) tasks(s ...string) *api.URL { return api.Action(w.Settings, "tasks", s...) }
func (w *Worker) codes(s ...string) *api.URL { return api.Action(w.Settings, "codes", s...) }
// create code package (zip) from parsed .worker info func pushCodes(zipName string, w *worker.Worker, args worker.Code) (id string, err error) { // TODO i don't get why i can't write from disk to wire, but I give up var body bytes.Buffer mWriter := multipart.NewWriter(&body) mMetaWriter, err := mWriter.CreateFormField("data") if err != nil { return "", err } jEncoder := json.NewEncoder(mMetaWriter) if err := jEncoder.Encode(args); err != nil { return "", err } if zipName != "" { r, err := zip.OpenReader(zipName) if err != nil { return "", err } defer r.Close() mFileWriter, err := mWriter.CreateFormFile("file", "worker.zip") if err != nil { return "", err } zWriter := zip.NewWriter(mFileWriter) for _, f := range r.File { fWriter, err := zWriter.Create(f.Name) if err != nil { return "", err } rc, err := f.Open() if err != nil { return "", err } _, err = io.Copy(fWriter, rc) rc.Close() if err != nil { return "", err } } zWriter.Close() } mWriter.Close() req, err := http.NewRequest("POST", api.Action(w.Settings, "codes").URL.String(), &body) if err != nil { return "", err } req.Header.Set("Accept", "application/json") req.Header.Set("Accept-Encoding", "gzip/deflate") req.Header.Set("Authorization", "OAuth "+w.Settings.Token) req.Header.Set("Content-Type", mWriter.FormDataContentType()) req.Header.Set("User-Agent", w.Settings.UserAgent) response, err := http.DefaultClient.Do(req) if err != nil { return "", err } if err = api.ResponseAsError(response); err != nil { return "", err } var data struct { Id string `json:"id"` } err = json.NewDecoder(response.Body).Decode(&data) return data.Id, err }