當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cmd.StreamJSONResponse函數代碼示例

本文整理匯總了Golang中github.com/tsuru/tsuru/cmd.StreamJSONResponse函數的典型用法代碼示例。如果您正苦於以下問題:Golang StreamJSONResponse函數的具體用法?Golang StreamJSONResponse怎麽用?Golang StreamJSONResponse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了StreamJSONResponse函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Run

func (c *moveContainerCmd) Run(context *cmd.Context, client *cmd.Client) error {
	context.RawOutput()
	url, err := cmd.GetURL(fmt.Sprintf("/docker/container/%s/move", context.Args[0]))
	if err != nil {
		return err
	}
	params := map[string]string{
		"to": context.Args[1],
	}
	b, err := json.Marshal(params)
	if err != nil {
		return err
	}
	buffer := bytes.NewBuffer(b)
	request, err := http.NewRequest("POST", url, buffer)
	if err != nil {
		return err
	}
	request.Header.Set("Content-Type", "application/json")
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	return cmd.StreamJSONResponse(context.Stdout, response)
}
開發者ID:nicolas2bonfils,項目名稱:tsuru,代碼行數:25,代碼來源:admin.go

示例2: removeServiceInstanceWithUnbind

func removeServiceInstanceWithUnbind(ctx *cmd.Context, client *cmd.Client) error {
	serviceName := ctx.Args[0]
	instanceName := ctx.Args[1]
	url := fmt.Sprintf("/services/%s/instances/%s?unbindall=%s", serviceName, instanceName, "true")
	url, err := cmd.GetURL(url)
	if err != nil {
		return err
	}
	request, err := http.NewRequest("DELETE", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(request)
	defer resp.Body.Close()
	if err != nil {
		return err
	}
	err = cmd.StreamJSONResponse(ctx.Stdout, resp)
	if err != nil {
		return err
	}
	fmt.Fprintf(ctx.Stdout, `Service "%s" successfully removed!`+"\n", instanceName)

	return nil
}
開發者ID:pauloalem,項目名稱:tsuru-client,代碼行數:25,代碼來源:services.go

示例3: Run

func (a *addNodeToSchedulerCmd) Run(ctx *cmd.Context, client *cmd.Client) error {
	jsonParams := map[string]string{}
	for _, param := range ctx.Args {
		if strings.Contains(param, "=") {
			keyValue := strings.SplitN(param, "=", 2)
			jsonParams[keyValue[0]] = keyValue[1]
		}
	}
	b, err := json.Marshal(jsonParams)
	if err != nil {
		return err
	}
	url, err := cmd.GetURL(fmt.Sprintf("/docker/node?register=%t", a.register))
	if err != nil {
		return err
	}
	req, err := http.NewRequest("POST", url, bytes.NewBuffer(b))
	if err != nil {
		return err
	}
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	err = cmd.StreamJSONResponse(ctx.Stdout, resp)
	if err != nil {
		return err
	}
	ctx.Stdout.Write([]byte("Node successfully registered.\n"))
	return nil
}
開發者ID:pedrosnk,項目名稱:tsuru,代碼行數:31,代碼來源:cmd.go

示例4: Run

func (p *platformUpdate) Run(context *cmd.Context, client *cmd.Client) error {
	context.RawOutput()
	name := context.Args[0]
	if p.disable && p.enable {
		return errors.New("Conflicting options: --enable and --disable\n")
	}
	if !p.disable && !p.enable && p.dockerfile == "" {
		return errors.New("Flag is required")
	}
	disable := ""
	if p.enable {
		disable = "false"
	}
	if p.disable {
		disable = "true"
	}
	body := fmt.Sprintf("a=1&dockerfile=%s", p.dockerfile)
	url, err := cmd.GetURL(fmt.Sprintf("/platforms/%s?disabled=%s", name, disable))
	request, err := http.NewRequest("PUT", url, strings.NewReader(body))
	if err != nil {
		return err
	}
	request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	return cmd.StreamJSONResponse(context.Stdout, response)
}
開發者ID:combor,項目名稱:tsuru-admin,代碼行數:29,代碼來源:platform.go

示例5: Run

func (c *rebalanceContainersCmd) Run(context *cmd.Context, client *cmd.Client) error {
	context.RawOutput()
	if !c.dry && !c.Confirm(context, "Are you sure you want to rebalance containers?") {
		return nil
	}
	u, err := cmd.GetURL("/docker/containers/rebalance")
	if err != nil {
		return err
	}
	opts := rebalanceOptions{
		Dry: c.dry,
	}
	if len(c.metadataFilter) > 0 {
		opts.MetadataFilter = c.metadataFilter
	}
	if len(c.appFilter) > 0 {
		opts.AppFilter = c.appFilter
	}
	v, err := form.EncodeToValues(&opts)
	if err != nil {
		return err
	}
	request, err := http.NewRequest("POST", u, bytes.NewBufferString(v.Encode()))
	if err != nil {
		return err
	}
	request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	return cmd.StreamJSONResponse(context.Stdout, response)
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:33,代碼來源:admin.go

示例6: Run

func (c *appPlanChange) Run(context *cmd.Context, client *cmd.Client) error {
	context.RawOutput()
	appName, err := c.Guess()
	if err != nil {
		return err
	}
	plan := tsuruapp.Plan{Name: context.Args[0]}
	question := fmt.Sprintf("Are you sure you want to change the plan of the application %q to %q?", appName, plan.Name)
	if !c.Confirm(context, question) {
		return nil
	}
	url, err := cmd.GetURL(fmt.Sprintf("/apps/%s/plan", appName))
	if err != nil {
		return err
	}
	b, err := json.Marshal(plan)
	if err != nil {
		return err
	}
	request, err := http.NewRequest("POST", url, bytes.NewReader(b))
	if err != nil {
		return err
	}
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	return cmd.StreamJSONResponse(context.Stdout, response)
}
開發者ID:axelerant,項目名稱:tsuru-client,代碼行數:29,代碼來源:plan.go

示例7: Run

func (c *unitAdd) Run(context *cmd.Context, client *cmd.Client) error {
	context.RawOutput()
	appName, err := c.Guess()
	if err != nil {
		return err
	}
	u, err := cmd.GetURL(fmt.Sprintf("/apps/%s/units", appName))
	if err != nil {
		return err
	}
	val := url.Values{}
	val.Add("units", context.Args[0])
	val.Add("process", c.process)
	request, err := http.NewRequest("PUT", u, bytes.NewBufferString(val.Encode()))
	if err != nil {
		return err
	}
	request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	return cmd.StreamJSONResponse(context.Stdout, response)
}
開發者ID:axelerant,項目名稱:tsuru-client,代碼行數:25,代碼來源:apps.go

示例8: Run

func (c *dockerLogUpdate) Run(context *cmd.Context, client *cmd.Client) error {
	context.RawOutput()
	if c.restart {
		extra := ""
		if c.pool != "" {
			extra = fmt.Sprintf(" running on pool %s", c.pool)
		}
		msg := fmt.Sprintf("Are you sure you want to restart all apps%s?", extra)
		if !c.Confirm(context, msg) {
			return nil
		}
	}
	url, err := cmd.GetURL("/docker/logs")
	if err != nil {
		return err
	}
	envList := []provision.Entry{
		{Name: "log-driver", Value: c.logDriver},
	}
	for name, value := range c.logOpts {
		envList = append(envList, provision.Entry{Name: name, Value: value})
	}
	conf := provision.ScopedConfig{}
	if c.pool == "" {
		conf.Envs = envList
	} else {
		conf.Pools = []provision.PoolEntry{{
			Name: c.pool,
			Envs: envList,
		}}
	}
	b, err := json.Marshal(logsSetData{
		Restart: c.restart,
		Config:  conf,
	})
	if err != nil {
		return err
	}
	buffer := bytes.NewBuffer(b)
	request, err := http.NewRequest("POST", url, buffer)
	if err != nil {
		return err
	}
	request.Header.Set("Content-Type", "application/json")
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	return cmd.StreamJSONResponse(context.Stdout, response)
}
開發者ID:zhenruyan,項目名稱:tsuru,代碼行數:51,代碼來源:cmd.go

示例9: Run

func (c *UpgradeCmd) Run(context *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/docker/bs/upgrade")
	if err != nil {
		return err
	}
	request, err := http.NewRequest("POST", url, nil)
	if err != nil {
		return err
	}
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	return cmd.StreamJSONResponse(context.Stdout, response)
}
開發者ID:nikolasmagno,項目名稱:tsuru,代碼行數:16,代碼來源:cmd.go

示例10: Run

func (c *appUpdate) Run(context *cmd.Context, client *cmd.Client) error {
	context.RawOutput()
	appName := context.Args[0]
	var param app
	if c.plan != "" {
		plan := tsuruapp.Plan{Name: c.plan}
		question := fmt.Sprintf("Are you sure you want to change the plan of the application %q to %q?", appName, plan.Name)
		if !c.Confirm(context, question) {
			return nil
		}
		param.Plan = plan
	}
	param.Description = c.description
	param.Pool = c.pool
	param.TeamOwner = c.teamOwner
	b, err := json.Marshal(param)
	if err != nil {
		return err
	}
	url, err := cmd.GetURL(fmt.Sprintf("/apps/%s", appName))
	if err != nil {
		return err
	}
	request, err := http.NewRequest("POST", url, bytes.NewBuffer(b))
	if err != nil {
		return err
	}
	request.Header.Set("Content-Type", "application/json")
	response, err := client.Do(request)
	if err != nil {
		e := err.(*tsuruerr.HTTP)
		if e.Code == http.StatusBadRequest {
			return errors.New("You must set a flag. Use the 'app-update --help' command for more information.")
		}
		return err
	}
	err = cmd.StreamJSONResponse(context.Stdout, response)
	if err != nil {
		return err
	}
	fmt.Fprintf(context.Stdout, "App %q has been updated!\n", appName)
	fmt.Fprintln(context.Stdout, "Use app-info to check the status of the app and its units.")
	return nil
}
開發者ID:pauloalem,項目名稱:tsuru-client,代碼行數:44,代碼來源:apps.go

示例11: Run

func (c *EnvSetCmd) Run(context *cmd.Context, client *cmd.Client) error {
	context.RawOutput()
	url, err := cmd.GetURL("/docker/bs/env")
	if err != nil {
		return err
	}
	var envList []provision.Entry
	for _, arg := range context.Args {
		parts := strings.SplitN(arg, "=", 2)
		if len(parts) < 2 {
			return fmt.Errorf("invalid variable values")
		}
		if parts[0] == "" {
			return fmt.Errorf("invalid variable values")
		}
		envList = append(envList, provision.Entry{Name: parts[0], Value: parts[1]})
	}
	conf := provision.ScopedConfig{}
	if c.pool == "" {
		conf.Envs = envList
	} else {
		conf.Pools = []provision.PoolEntry{{
			Name: c.pool,
			Envs: envList,
		}}
	}
	b, err := json.Marshal(conf)
	if err != nil {
		return err
	}
	buffer := bytes.NewBuffer(b)
	request, err := http.NewRequest("POST", url, buffer)
	if err != nil {
		return err
	}
	request.Header.Set("Content-Type", "application/json")
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	return cmd.StreamJSONResponse(context.Stdout, response)
}
開發者ID:botvs,項目名稱:tsuru,代碼行數:43,代碼來源:cmd.go

示例12: Run

func (c *dockerLogUpdate) Run(context *cmd.Context, client *cmd.Client) error {
	context.RawOutput()
	if c.restart {
		extra := ""
		if c.pool != "" {
			extra = fmt.Sprintf(" running on pool %s", c.pool)
		}
		msg := fmt.Sprintf("Are you sure you want to restart all apps%s?", extra)
		if !c.Confirm(context, msg) {
			return nil
		}
	}
	u, err := cmd.GetURL("/docker/logs")
	if err != nil {
		return err
	}
	conf := container.DockerLogConfig{
		Driver:  c.logDriver,
		LogOpts: map[string]string(c.logOpts),
	}
	values, err := form.EncodeToValues(conf)
	if err != nil {
		return err
	}
	values.Set("pool", c.pool)
	values.Set("restart", strconv.FormatBool(c.restart))
	reader := strings.NewReader(values.Encode())
	request, err := http.NewRequest("POST", u, reader)
	if err != nil {
		return err
	}
	request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	return cmd.StreamJSONResponse(context.Stdout, response)
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:39,代碼來源:cmd.go


注:本文中的github.com/tsuru/tsuru/cmd.StreamJSONResponse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。