• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang cmd.Table类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/tsuru/tsuru/cmd.Table的典型用法代码示例。如果您正苦于以下问题:Golang Table类的具体用法?Golang Table怎么用?Golang Table使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Table类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Run

func (c *keyList) Run(context *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/users/keys")
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(request)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	var keys map[string]string
	err = json.NewDecoder(resp.Body).Decode(&keys)
	if err != nil {
		return err
	}
	var table cmd.Table
	table.Headers = cmd.Row{"Name", "Content"}
	table.LineSeparator = c.notrunc
	for name, content := range keys {
		row := []string{name, content}
		if !c.notrunc && len(row[1]) > keyTruncate {
			row[1] = row[1][:keyTruncate] + "..."
		}
		table.AddRow(cmd.Row(row))
	}
	table.SortByColumn(0)
	context.Stdout.Write(table.Bytes())
	return nil
}
开发者ID:axelerant,项目名称:tsuru-client,代码行数:33,代码来源:key.go


示例2: Run

func (c *InfoCmd) Run(context *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/docker/bs")
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	var conf provision.ScopedConfig
	err = json.NewDecoder(response.Body).Decode(&conf)
	if err != nil {
		return err
	}
	fmt.Fprintf(context.Stdout, "Image: %s\n\nEnvironment Variables [Default]:\n", conf.Extra["image"])
	t := cmd.Table{Headers: cmd.Row([]string{"Name", "Value"})}
	for _, envVar := range conf.Envs {
		t.AddRow(cmd.Row([]string{envVar.Name, fmt.Sprintf("%v", envVar.Value)}))
	}
	context.Stdout.Write(t.Bytes())
	for _, pool := range conf.Pools {
		t := cmd.Table{Headers: cmd.Row([]string{"Name", "Value"})}
		fmt.Fprintf(context.Stdout, "\nEnvironment Variables [%s]:\n", pool.Name)
		for _, envVar := range pool.Envs {
			t.AddRow(cmd.Row([]string{envVar.Name, fmt.Sprintf("%v", envVar.Value)}))
		}
		context.Stdout.Write(t.Bytes())
	}
	return nil
}
开发者ID:botvs,项目名称:tsuru,代码行数:35,代码来源:cmd.go


示例3: Run

func (listPoolsInTheSchedulerCmd) Run(ctx *cmd.Context, client *cmd.Client) error {
	t := cmd.Table{Headers: cmd.Row([]string{"Pools", "Teams"})}
	url, err := cmd.GetURL("/docker/pool")
	if err != nil {
		return err
	}
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	var pools []Pool
	err = json.Unmarshal(body, &pools)
	for _, p := range pools {
		t.AddRow(cmd.Row([]string{p.Name, strings.Join(p.Teams, ", ")}))
	}
	t.Sort()
	ctx.Stdout.Write(t.Bytes())
	return nil
}
开发者ID:rualatngua,项目名称:tsuru,代码行数:25,代码来源:scheduler.go


示例4: Run

func (listNodesInTheSchedulerCmd) Run(ctx *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/node")
	if err != nil {
		return err
	}
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	var nodes []map[string]string
	err = json.Unmarshal(body, &nodes)
	t := cmd.Table{Headers: cmd.Row([]string{"Address"})}
	for _, n := range nodes {
		t.AddRow(cmd.Row([]string{n["Address"]}))
	}
	t.Sort()
	ctx.Stdout.Write(t.Bytes())
	return nil
}
开发者ID:rochacon,项目名称:tsuru,代码行数:25,代码来源:cmd.go


示例5: Run

func (listPoolsInTheSchedulerCmd) Run(ctx *cmd.Context, client *cmd.Client) error {
	t := cmd.Table{Headers: cmd.Row([]string{"Pools", "Teams", "Public"})}
	url, err := cmd.GetURL("/pool")
	if err != nil {
		return err
	}
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	var pools []provision.Pool
	err = json.Unmarshal(body, &pools)
	for _, p := range pools {
		public := ""
		if p.Public {
			public = "   X   "
		}
		defaultFlag := ""
		if p.Default {
			defaultFlag = " (default)"
		}
		t.AddRow(cmd.Row([]string{p.Name + defaultFlag, strings.Join(p.Teams, ", "), public}))
	}
	t.Sort()
	ctx.Stdout.Write(t.Bytes())
	return nil
}
开发者ID:combor,项目名称:tsuru-admin,代码行数:33,代码来源:pool.go


示例6: render

func (c *autoScaleInfoCmd) render(context *cmd.Context, config *autoScaleConfig, rules []autoScaleRule) error {
	fmt.Fprintf(context.Stdout, "Metadata filter: %s\n\n", config.GroupByMetadata)
	var table cmd.Table
	tableHeader := []string{
		"Filter value",
		"Max container count",
		"Max memory ratio",
		"Scale down ratio",
		"Rebalance on scale",
		"Enabled",
	}
	table.Headers = tableHeader
	for _, rule := range rules {
		table.AddRow([]string{
			rule.MetadataFilter,
			strconv.Itoa(rule.MaxContainerCount),
			strconv.FormatFloat(float64(rule.MaxMemoryRatio), 'f', 4, 32),
			strconv.FormatFloat(float64(rule.ScaleDownRatio), 'f', 4, 32),
			strconv.FormatBool(!rule.PreventRebalance),
			strconv.FormatBool(rule.Enabled),
		})
	}
	fmt.Fprintf(context.Stdout, "Rules:\n%s", table.String())
	return nil
}
开发者ID:Endika,项目名称:tsuru,代码行数:25,代码来源:cmd.go


示例7: renderHistoryTable

func renderHistoryTable(history []healingEvent, filter string, ctx *cmd.Context) {
	fmt.Fprintln(ctx.Stdout, strings.ToUpper(filter[:1])+filter[1:]+":")
	headers := cmd.Row([]string{"Start", "Finish", "Success", "Failing", "Created", "Error"})
	t := cmd.Table{Headers: headers}
	for i := len(history) - 1; i >= 0; i-- {
		event := history[i]
		if event.Action != filter+"-healing" {
			continue
		}
		data := make([]string, 2)
		if filter == "node" {
			data[0] = event.FailingNode.Address
			data[1] = event.CreatedNode.Address
		} else {
			data[0] = event.FailingContainer.ID
			data[1] = event.CreatedContainer.ID
			if len(data[0]) > 10 {
				data[0] = data[0][:10]
			}
			if len(data[1]) > 10 {
				data[1] = data[1][:10]
			}
		}
		t.AddRow(cmd.Row([]string{
			event.StartTime.Local().Format(time.Stamp),
			event.EndTime.Local().Format(time.Stamp),
			fmt.Sprintf("%t", event.Successful),
			data[0],
			data[1],
			event.Error,
		}))
	}
	t.LineSeparator = true
	ctx.Stdout.Write(t.Bytes())
}
开发者ID:RichardKnop,项目名称:tsuru,代码行数:35,代码来源:cmd.go


示例8: Run

func (listNodesInTheSchedulerCmd) Run(ctx *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/docker/node")
	if err != nil {
		return err
	}
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	var result map[string]interface{}
	err = json.NewDecoder(resp.Body).Decode(&result)
	if err != nil {
		return err
	}
	machineMap := map[string]map[string]interface{}{}
	if result["machines"] != nil {
		machines := result["machines"].([]interface{})
		for _, m := range machines {
			machine := m.(map[string]interface{})
			machineMap[machine["Address"].(string)] = m.(map[string]interface{})
		}
	}
	t := cmd.Table{Headers: cmd.Row([]string{"Address", "IaaS ID", "Status", "Metadata"}), LineSeparator: true}
	var nodes []interface{}
	if result["nodes"] != nil {
		nodes = result["nodes"].([]interface{})
	}
	for _, n := range nodes {
		node := n.(map[string]interface{})
		addr := node["Address"].(string)
		status := node["Status"].(string)
		result := []string{}
		metadataField, _ := node["Metadata"]
		if metadataField != nil {
			metadata := metadataField.(map[string]interface{})
			for key, value := range metadata {
				result = append(result, fmt.Sprintf("%s=%s", key, value.(string)))
			}
		}
		sort.Strings(result)
		m, ok := machineMap[urlToHost(addr)]
		var iaasId string
		if ok {
			iaasId = m["Id"].(string)
		}
		t.AddRow(cmd.Row([]string{addr, iaasId, status, strings.Join(result, "\n")}))
	}
	t.Sort()
	ctx.Stdout.Write(t.Bytes())
	return nil
}
开发者ID:rualatngua,项目名称:tsuru,代码行数:55,代码来源:cmd.go


示例9: Run

func (listNodesInTheSchedulerCmd) Run(ctx *cmd.Context, client *cmd.Client) error {
	t := cmd.Table{Headers: cmd.Row([]string{"ID", "Address", "Team"})}
	nodes, err := listNodesInTheScheduler()
	if err != nil {
		return err
	}
	for _, n := range nodes {
		t.AddRow(cmd.Row([]string{n.ID, n.Address, strings.Join(n.Teams, ", ")}))
	}
	t.Sort()
	ctx.Stdout.Write(t.Bytes())
	return nil
}
开发者ID:kennylixi,项目名称:tsuru,代码行数:13,代码来源:scheduler.go


示例10: Run

func (c *listAutoScaleHistoryCmd) Run(ctx *cmd.Context, client *cmd.Client) error {
	if c.page < 1 {
		c.page = 1
	}
	limit := 20
	skip := (c.page - 1) * limit
	u, err := cmd.GetURL(fmt.Sprintf("/docker/autoscale?skip=%d&limit=%d", skip, limit))
	if err != nil {
		return err
	}
	req, err := http.NewRequest("GET", u, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	var history []autoScaleEvent
	if resp.StatusCode == 204 {
		ctx.Stdout.Write([]byte("There is no auto scales yet.\n"))
		return nil
	}
	err = json.NewDecoder(resp.Body).Decode(&history)
	if err != nil {
		return err
	}
	headers := cmd.Row([]string{"Start", "Finish", "Success", "Metadata", "Action", "Reason", "Error"})
	t := cmd.Table{Headers: headers}
	for i := range history {
		event := &history[i]
		t.AddRow(cmd.Row([]string{
			event.StartTime.Local().Format(time.Stamp),
			checkEndOfEvent(event),
			fmt.Sprintf("%t", event.Successful),
			event.MetadataValue,
			event.Action,
			event.Reason,
			event.Error,
		}))
	}
	t.LineSeparator = true
	ctx.Stdout.Write(t.Bytes())
	return nil
}
开发者ID:tsuru,项目名称:tsuru,代码行数:46,代码来源:cmd.go


示例11: Run

func (c *dockerLogInfo) Run(context *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/docker/logs")
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	var conf provision.ScopedConfig
	err = json.NewDecoder(response.Body).Decode(&conf)
	if err != nil {
		return err
	}
	t := cmd.Table{Headers: cmd.Row([]string{"Name", "Value"})}
	for _, envVar := range conf.Envs {
		if envVar.Name == container.DockerLogDriverConfig {
			fmt.Fprintf(context.Stdout, "Log driver [default]: %s\n", envVar.Value)
			continue
		}
		t.AddRow(cmd.Row([]string{envVar.Name, fmt.Sprintf("%v", envVar.Value)}))
	}
	if t.Rows() > 0 {
		t.Sort()
		context.Stdout.Write(t.Bytes())
	}
	sort.Sort(provision.ConfigPoolEntryList(conf.Pools))
	for _, pool := range conf.Pools {
		t := cmd.Table{Headers: cmd.Row([]string{"Name", "Value"})}
		for _, envVar := range pool.Envs {
			if envVar.Name == container.DockerLogDriverConfig {
				fmt.Fprintf(context.Stdout, "\nLog driver [pool %s]: %s\n", pool.Name, envVar.Value)
				continue
			}
			t.AddRow(cmd.Row([]string{envVar.Name, fmt.Sprintf("%v", envVar.Value)}))
		}
		if t.Rows() > 0 {
			t.Sort()
			context.Stdout.Write(t.Bytes())
		}
	}
	return nil
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:48,代码来源:cmd.go


示例12: Run

func (poolList) Run(context *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/pools")
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(request)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	var pools ListPoolResponse
	err = json.NewDecoder(resp.Body).Decode(&pools)
	if err != nil {
		return err
	}
	t := cmd.Table{Headers: cmd.Row([]string{"Team", "Pools"})}
	for _, pool := range pools.PoolsByTeam {
		t.AddRow(cmd.Row([]string{pool.Team, strings.Join(pool.Pools, ", ")}))
	}
	t.Sort()
	context.Stdout.Write(t.Bytes())
	tp := cmd.Table{Headers: cmd.Row([]string{"Public Pools"})}
	for _, pool := range pools.PublicPools {
		tp.AddRow(cmd.Row([]string{pool.Name}))
	}
	tp.Sort()
	context.Stdout.Write([]byte("\n"))
	context.Stdout.Write(tp.Bytes())
	if len(pools.DefaultPools) > 0 {
		td := cmd.Table{Headers: cmd.Row([]string{"Default Pool"})}
		td.AddRow(cmd.Row([]string{pools.DefaultPools[0].Name}))
		context.Stdout.Write([]byte("\n"))
		context.Stdout.Write(td.Bytes())
	}
	return nil
}
开发者ID:wpjunior,项目名称:tsuru-client,代码行数:40,代码来源:pool.go



注:本文中的github.com/tsuru/tsuru/cmd.Table类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang db.Conn函数代码示例发布时间:2022-05-28
下一篇:
Golang cmd.Manager类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap