本文整理汇总了Golang中github.com/iron-io/iron_go3/api.Action函数的典型用法代码示例。如果您正苦于以下问题:Golang Action函数的具体用法?Golang Action怎么用?Golang Action使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Action函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ListQueues
func ListQueues(s config.Settings, prefix, prev string, perPage int) ([]Queue, error) {
var out struct {
Queues []Queue `json:"queues"`
}
url := api.Action(s, "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
}
for idx := range out.Queues {
out.Queues[idx].Settings = s
}
return out.Queues, nil
}
开发者ID:nildev,项目名称:prj-tpl-basic-api,代码行数:28,代码来源:mq.go
示例2: dockerLogin
func dockerLogin(w *worker.Worker, args *map[string]string) (msg string, err error) {
data, err := json.Marshal(args)
reader := bytes.NewReader(data)
req, err := http.NewRequest("POST", api.Action(w.Settings, "credentials").URL.String(), reader)
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", "application/json")
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 res struct {
Msg string `json:"msg"`
}
err = json.NewDecoder(response.Body).Decode(&res)
return res.Msg, err
}
开发者ID:romand,项目名称:ironcli,代码行数:33,代码来源:worker.go
示例3: main
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)
}
开发者ID:toshipon,项目名称:iron_go3,代码行数:54,代码来源:main.go
示例4: ConfigCreateQueue
// Will create a new queue, all fields are optional.
// Queue type cannot be changed.
func ConfigCreateQueue(queueInfo QueueInfo, settings *config.Settings) (QueueInfo, error) {
if queueInfo.Name == "" {
return QueueInfo{}, errors.New("Name of queue is empty")
}
url := api.Action(config.ManualConfig("iron_mq", settings), "queues", queueInfo.Name)
in := struct {
Queue QueueInfo `json:"queue"`
}{
Queue: queueInfo,
}
var out struct {
Queue QueueInfo `json:"queue"`
}
err := url.Req("PUT", in, &out)
return out.Queue, err
}
开发者ID:romand,项目名称:ironcli,代码行数:22,代码来源:mq.go
示例5: listQueues
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
}
开发者ID:romand,项目名称:ironcli,代码行数:24,代码来源:mq.go
示例6: schedules
func (w *Worker) schedules(s ...string) *api.URL { return api.Action(w.Settings, "schedules", s...) }
开发者ID:alex-litvak,项目名称:iron_go3,代码行数:1,代码来源:worker.go
示例7: tasks
func (w *Worker) tasks(s ...string) *api.URL { return api.Action(w.Settings, "tasks", s...) }
开发者ID:alex-litvak,项目名称:iron_go3,代码行数:1,代码来源:worker.go
示例8: codes
func (w *Worker) codes(s ...string) *api.URL { return api.Action(w.Settings, "codes", s...) }
开发者ID:alex-litvak,项目名称:iron_go3,代码行数:1,代码来源:worker.go
示例9: queues
func (q Queue) queues(s ...string) *api.URL { return api.Action(q.Settings, "queues", s...) }
开发者ID:romand,项目名称:ironcli,代码行数:1,代码来源:mq.go
示例10: caches
func (c *Cache) caches(suffix ...string) *api.URL {
return api.Action(c.Settings, "caches", suffix...)
}
开发者ID:toshipon,项目名称:iron_go3,代码行数:3,代码来源:cache.go
示例11: pushCodes
// create code package (zip) from parsed .worker info
func pushCodes(zipName string, w *worker.Worker, args worker.Code) (*worker.Code, 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 nil, err
}
jEncoder := json.NewEncoder(mMetaWriter)
if err := jEncoder.Encode(args); err != nil {
return nil, err
}
if zipName != "" {
r, err := zip.OpenReader(zipName)
if err != nil {
return nil, err
}
defer r.Close()
mFileWriter, err := mWriter.CreateFormFile("file", "worker.zip")
if err != nil {
return nil, err
}
zWriter := zip.NewWriter(mFileWriter)
for _, f := range r.File {
fWriter, err := zWriter.Create(f.Name)
if err != nil {
return nil, err
}
rc, err := f.Open()
if err != nil {
return nil, err
}
_, err = io.Copy(fWriter, rc)
rc.Close()
if err != nil {
return nil, err
}
}
zWriter.Close()
}
mWriter.Close()
req, err := http.NewRequest("POST", api.Action(w.Settings, "codes").URL.String(), &body)
if err != nil {
return nil, 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 nil, err
}
if err = api.ResponseAsError(response); err != nil {
return nil, err
}
var data worker.Code
err = json.NewDecoder(response.Body).Decode(&data)
return &data, err
}
开发者ID:romand,项目名称:ironcli,代码行数:72,代码来源:worker.go
注:本文中的github.com/iron-io/iron_go3/api.Action函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论