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


Golang Context.Bool方法代碼示例

本文整理匯總了Golang中github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli.Context.Bool方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Bool方法的具體用法?Golang Context.Bool怎麽用?Golang Context.Bool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli.Context的用法示例。


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

示例1: 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

示例2: dropletCreate

func dropletCreate(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		log.Fatal("Error: Must provide name for Droplet.")
	}

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

	// Add domain to end if available.
	dropletName := ctx.Args().First()
	if ctx.Bool("add-region") {
		dropletName = fmt.Sprintf("%s.%s", dropletName, ctx.String("region"))
	}
	if ctx.String("domain") != "" {
		dropletName = fmt.Sprintf("%s.%s", dropletName, ctx.String("domain"))
	}

	// Loop through the SSH Keys and add by name. DO API should have handled
	// this case as well.
	var sshKeys []godo.DropletCreateSSHKey
	keyNames := ctx.String("ssh-keys")
	if keyNames != "" {
		for _, keyName := range strings.Split(keyNames, ",") {
			sshKey, err := FindKeyByName(client, keyName)
			if sshKey != nil && err == nil {
				sshKeys = append(sshKeys, godo.DropletCreateSSHKey{ID: sshKey.ID})
			} else {
				log.Fatalf("Warning: Could not find key: %q.", keyName)
			}
		}
	}

	userData := ""
	userDataPath := ctx.String("user-data-file")
	if userDataPath != "" {
		file, err := os.Open(userDataPath)
		if err != nil {
			log.Fatalf("Error opening user data file: %s.", err)
		}

		userDataFile, err := ioutil.ReadAll(file)
		if err != nil {
			log.Fatalf("Error reading user data file: %s.", err)
		}
		userData = string(userDataFile)
	} else {
		userData = ctx.String("user-data")
	}

	createRequest := &godo.DropletCreateRequest{
		Name:   dropletName,
		Region: ctx.String("region"),
		Size:   ctx.String("size"),
		Image: godo.DropletCreateImage{
			Slug: ctx.String("image"),
		},
		SSHKeys:           sshKeys,
		Backups:           ctx.Bool("backups"),
		IPv6:              ctx.Bool("ipv6"),
		PrivateNetworking: ctx.Bool("private-networking"),
		UserData:          userData,
	}

	droplet, resp, err := client.Droplets.Create(createRequest)
	if err != nil {
		log.Fatalf("Unable to create Droplet: %s.", err)
	}

	if ctx.Bool("wait-for-active") {
		util.WaitForActive(client, resp.Links.Actions[0].HREF)
	}
	WriteOutput(droplet)
}
開發者ID:wojtekzw,項目名稱:doctl,代碼行數:76,代碼來源:droplet.go


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