当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Int方法代码示例

本文整理汇总了Golang中github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli.Context.Int方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Int方法的具体用法?Golang Context.Int怎么用?Golang Context.Int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli.Context的用法示例。


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

示例1: actionList

func actionList(ctx *cli.Context) {
	if ctx.BoolT("help") == true {
		cli.ShowAppHelp(ctx)
		os.Exit(1)
	}

	tokenSource := &TokenSource{
		AccessToken: APIKey,
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	client := godo.NewClient(oauthClient)

	opt := &godo.ListOptions{
		Page:    ctx.Int("page"),
		PerPage: ctx.Int("page-size"),
	}
	actionList, _, err := client.Actions.List(opt)

	if err != nil {
		fmt.Printf("Unable to list Actions: %s\n", err)
		os.Exit(1)
	}

	cliOut := NewCLIOutput()
	defer cliOut.Flush()
	cliOut.Header("ID", "Region", "ResourceType", "ResourceID", "Type", "StartedAt", "CompletedAt", "Status")
	for _, action := range actionList {
		cliOut.Writeln("%d\t%s\t%s\t%d\t%s\t%s\t%s\t%s\n",
			action.ID, action.RegionSlug, action.ResourceType, action.ResourceID, action.Type, action.StartedAt, action.CompletedAt, action.Status)
	}
}
开发者ID:jmptrader,项目名称:doctl,代码行数:31,代码来源:action.go

示例2: dropletActionUpgrade

func dropletActionUpgrade(ctx *cli.Context) {
	if ctx.Int("id") == 0 && len(ctx.Args()) != 1 {
		log.Fatal("Error: Must provide ID or name for Droplet to resize.")
	}

	tokenSource := &TokenSource{
		AccessToken: APIKey,
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	client := godo.NewClient(oauthClient)

	id := ctx.Int("id")
	if id == 0 {
		droplet, err := FindDropletByName(client, ctx.Args()[0])
		if err != nil {
			log.Fatal(err)
		} else {
			id = droplet.ID
		}
	}

	droplet, _, err := client.Droplets.Get(id)
	if err != nil {
		log.Fatal("Unable to find Droplet: %s.", err)
	}

	action, _, err := client.DropletActions.Upgrade(droplet.ID)
	if err != nil {
		log.Fatal(err)
	}

	WriteOutput(action)
}
开发者ID:wojtekzw,项目名称:doctl,代码行数:33,代码来源:droplet.go

示例3: dropletDestroy

func dropletDestroy(ctx *cli.Context) {
	if ctx.Int("id") == 0 && len(ctx.Args()) != 1 {
		log.Fatal("Error: Must provide ID or name for Droplet to destroy.")
	}

	tokenSource := &TokenSource{
		AccessToken: APIKey,
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	client := godo.NewClient(oauthClient)

	id := ctx.Int("id")
	if id == 0 {
		droplet, err := FindDropletByName(client, ctx.Args()[0])
		if err != nil {
			log.Fatal(err)
		} else {
			id = droplet.ID
		}
	}

	droplet, _, err := client.Droplets.Get(id)
	if err != nil {
		log.Fatalf("Unable to find Droplet: %s.", err)
	}

	_, err = client.Droplets.Delete(id)
	if err != nil {
		log.Fatalf("Unable to destroy Droplet: %s.", err)
	}

	log.Fatalf("Droplet %s destroyed.", droplet.Name)
}
开发者ID:wojtekzw,项目名称:doctl,代码行数:33,代码来源:droplet.go

示例4: domainList

func domainList(ctx *cli.Context) {
	if ctx.BoolT("help") == true {
		cli.ShowAppHelp(ctx)
		os.Exit(1)
	}

	tokenSource := &TokenSource{
		AccessToken: APIKey,
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	client := godo.NewClient(oauthClient)

	opt := &godo.ListOptions{
		Page:    ctx.Int("page"),
		PerPage: ctx.Int("page-size"),
	}
	domainList, _, err := client.Domains.List(opt)
	if err != nil {
		log.Fatalf("Unable to list Domains: %s.", err)
	}

	cliOut := NewCLIOutput()
	defer cliOut.Flush()
	cliOut.Header("Name", "TTL")
	for _, domain := range domainList {
		cliOut.Writeln("%s\t%d\n", domain.Name, domain.TTL)
	}
}
开发者ID:phillbaker,项目名称:doctl,代码行数:28,代码来源:domain.go

示例5: domainRecordList

func domainRecordList(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		fmt.Printf("Error: Must provide a domain name for which to list records.\n")
		os.Exit(64)
	}

	tokenSource := &TokenSource{
		AccessToken: APIKey,
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	client := godo.NewClient(oauthClient)

	domainName := ctx.Args().First()

	opt := &godo.ListOptions{
		Page:    ctx.Int("page"),
		PerPage: ctx.Int("page-size"),
	}
	domainDecords, _, err := client.Domains.Records(domainName, opt)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	}

	WriteOutput(domainDecords)
}
开发者ID:jmptrader,项目名称:doctl,代码行数:26,代码来源:domain.go

示例6: sshDestroy

func sshDestroy(ctx *cli.Context) {
	if ctx.Int("id") == 0 && ctx.String("fingerprint") == "" && len(ctx.Args()) < 1 {
		fmt.Printf("Error: Must provide ID, fingerprint or name for SSH Key to destroy.\n")
		os.Exit(1)
	}

	tokenSource := &TokenSource{
		AccessToken: APIKey,
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	client := godo.NewClient(oauthClient)

	id := ctx.Int("id")
	fingerprint := ctx.String("fingerprint")
	var key godo.Key
	if id == 0 && fingerprint == "" {
		key, err := FindKeyByName(client, ctx.Args().First())
		if err != nil {
			fmt.Printf("%s\n", err)
			os.Exit(64)
		} else {
			id = key.ID
		}
	} else if id != 0 {
		key, _, err := client.Keys.GetByID(id)
		if err != nil {
			fmt.Printf("Unable to find SSH Key: %s\n", err)
			os.Exit(1)
		} else {
			id = key.ID
		}
	} else {
		key, _, err := client.Keys.GetByFingerprint(fingerprint)
		if err != nil {
			fmt.Printf("Unable to find SSH Key: %s\n", err)
			os.Exit(1)
		} else {
			id = key.ID
		}
	}

	_, err := client.Keys.DeleteByID(id)
	if err != nil {
		fmt.Printf("Unable to destroy SSH Key: %s\n", err)
		os.Exit(1)
	}

	fmt.Printf("Key %s destroyed.\n", key.Name)
}
开发者ID:jmptrader,项目名称:doctl,代码行数:49,代码来源:sshkey.go

示例7: dropletActionResize

func dropletActionResize(ctx *cli.Context) {
	if ctx.Int("id") == 0 && len(ctx.Args()) != 1 {
		fmt.Printf("Error: Must provide ID or name for Droplet to destroy.\n")
		os.Exit(1)
	}

	size := ctx.String("size")
	disk := ctx.Bool("disk")

	tokenSource := &TokenSource{
		AccessToken: APIKey,
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	client := godo.NewClient(oauthClient)

	id := ctx.Int("id")
	if id == 0 {
		droplet, err := FindDropletByName(client, ctx.Args()[0])
		if err != nil {
			fmt.Printf("%s\n", err)
			os.Exit(64)
		} else {
			id = droplet.ID
		}
	}

	droplet, _, err := client.Droplets.Get(id)
	if err != nil {
		fmt.Printf("Unable to find Droplet: %s\n", err)
		os.Exit(1)
	}

	action, _, err := client.DropletActions.Resize(droplet.ID, size, disk)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	WriteOutput(action)
}
开发者ID:jmptrader,项目名称:doctl,代码行数:40,代码来源:droplet.go

示例8: domainRecordCreate

func domainRecordCreate(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		cli.ShowAppHelp(ctx)
		fmt.Printf("Must specify a domain name to add a record to.\n")
		os.Exit(1)
	}

	domainName := ctx.Args().First()

	tokenSource := &TokenSource{
		AccessToken: APIKey,
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	client := godo.NewClient(oauthClient)

	createRequest := &godo.DomainRecordEditRequest{
		Type: strings.ToUpper(ctx.String("type")),
		Name: ctx.String("name"),
		Data: ctx.String("data"),
	}

	if createRequest.Type == "MX" || createRequest.Type == "SRV" {
		createRequest.Priority = ctx.Int("priority")
	}
	if createRequest.Type == "SRV" {
		createRequest.Port = ctx.Int("port")
		createRequest.Weight = ctx.Int("weight")
	}

	domainRecord, _, err := client.Domains.CreateRecord(domainName, createRequest)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	}

	WriteOutput(domainRecord)
}
开发者ID:jmptrader,项目名称:doctl,代码行数:37,代码来源:domain.go

示例9: dropletActionKernels

func dropletActionKernels(ctx *cli.Context) {
	if ctx.Int("id") == 0 && len(ctx.Args()) != 1 {
		log.Fatal("Error: Must provide ID or name for Droplet to list available kernels.")
	}

	tokenSource := &TokenSource{
		AccessToken: APIKey,
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	client := godo.NewClient(oauthClient)

	id := ctx.Int("id")
	if id == 0 {
		droplet, err := FindDropletByName(client, ctx.Args()[0])
		if err != nil {
			log.Fatal(err)
		} else {
			id = droplet.ID
		}
	}

	droplet, _, err := client.Droplets.Get(id)
	if err != nil {
		log.Fatal("Unable to find Droplet: %s.", err)
	}

	opt := &godo.ListOptions{}
	kernelList := []godo.Kernel{}

	for { // TODO make all optional
		kernelsPage, resp, err := client.Droplets.Kernels(droplet.ID, opt)
		if err != nil {
			log.Fatalf("Unable to list Droplet kernels: %s.", err)
		}

		// append the current page's droplets to our list
		for _, k := range kernelsPage {
			kernelList = append(kernelList, k)
		}

		// if we are at the last page, break out the for loop
		if resp.Links == nil || resp.Links.IsLastPage() {
			break
		}

		page, err := resp.Links.CurrentPage()
		if err != nil {
			log.Fatalf("Unable to get pagination: %s.", err)
		}

		// set the page we want for the next request
		opt.Page = page + 1
	}

	cliOut := NewCLIOutput()
	defer cliOut.Flush()
	cliOut.Header("ID", "Name", "Version")
	for _, kernel := range kernelList {
		cliOut.Writeln("%d\t%s\t%s\n",
			kernel.ID, kernel.Name, kernel.Version)
	}

}
开发者ID:wojtekzw,项目名称:doctl,代码行数:63,代码来源:droplet.go


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