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


Golang godo.NewClient函数代码示例

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


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

示例1: sshCreate

func sshCreate(ctx *cli.Context) {
	if len(ctx.Args()) != 2 {
		log.Fatal("Must provide name and public key file.")
	}

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

	file, err := os.Open(ctx.Args()[1])
	if err != nil {
		log.Fatalf("Error opening key file: %s.", err)
	}

	keyData, err := ioutil.ReadAll(file)
	if err != nil {
		log.Fatalf("Error reading key file: %s.", err)
	}

	createRequest := &godo.KeyCreateRequest{
		Name:      ctx.Args().First(),
		PublicKey: string(keyData),
	}
	key, _, err := client.Keys.Create(createRequest)
	if err != nil {
		log.Fatal(err)
	}

	WriteOutput(key)
}
开发者ID:phillbaker,项目名称:doctl,代码行数:32,代码来源:sshkey.go

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

示例3: domainRecordDestroy

func domainRecordDestroy(ctx *cli.Context) {
	if len(ctx.Args()) != 2 {
		fmt.Printf("Error: Must provide domain name and domain record id.\n")
		os.Exit(1)
	}

	domainName := ctx.Args().First()
	recordID, err := strconv.Atoi(ctx.Args()[1])
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	}

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

	_, err = client.Domains.DeleteRecord(domainName, recordID)
	if err != nil {
		fmt.Printf("Unable to destroy domain record: %s\n", err)
		os.Exit(1)
	}

	fmt.Printf("Domain record %d destroyed.\n", recordID)
}
开发者ID:jmptrader,项目名称:doctl,代码行数:27,代码来源:domain.go

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

示例5: domainRecordShow

func domainRecordShow(ctx *cli.Context) {
	if len(ctx.Args()) == 2 {
		fmt.Printf("Error: Must provide domain name and domain record id.\n")
		os.Exit(64)
	}

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

	domainName := ctx.Args().First()
	recordID, err := strconv.Atoi(ctx.Args()[1])
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	}

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

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

示例6: regionList

func regionList(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:    1,
		PerPage: 50, // Not likely to have more than 50 regions soon
	}
	regionList, _, err := client.Regions.List(opt)
	if err != nil {
		fmt.Printf("Unable to list Regions: %s\n", err)
		os.Exit(1)
	}

	cliOut := NewCLIOutput()
	defer cliOut.Flush()
	cliOut.Header("Name", "Slug", "Available")
	for _, region := range regionList {
		cliOut.Writeln("%s\t%s\t%t\n", region.Name, region.Slug, region.Available)
	}
}
开发者ID:jmptrader,项目名称:doctl,代码行数:29,代码来源:region.go

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

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

示例9: domainCreate

func domainCreate(ctx *cli.Context) {
	if len(ctx.Args()) != 2 {
		log.Fatal("Must provide domain name and Droplet name.")
	}

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

	droplet, err := FindDropletByName(client, ctx.Args()[1])
	if err != nil {
		log.Fatal(err)
	}

	createRequest := &godo.DomainCreateRequest{
		Name:      ctx.Args().First(),
		IPAddress: PublicIPForDroplet(droplet),
	}
	domain, _, err := client.Domains.Create(createRequest)
	if err != nil {
		log.Fatal(err)
	}

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

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

示例11: sizeList

func sizeList(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:    1,
		PerPage: 50, // Not likely to have more than 50 sizes soon
	}
	sizeList, _, err := client.Sizes.List(opt)
	if err != nil {
		fmt.Printf("Unable to list Sizes: %s\n", err)
		os.Exit(1)
	}

	cliOut := NewCLIOutput()
	defer cliOut.Flush()
	cliOut.Header("Slug", "Memory", "VCPUs", "Disk", "Transfer", "Price Monthly", "Price Hourly")
	for _, size := range sizeList {
		cliOut.Writeln("%s\t%dMB\t%d\t%dGB\t%d\t$%.0f\t$%.5f\n",
			size.Slug, size.Memory, size.Vcpus, size.Disk, size.Transfer, size.PriceMonthly, size.PriceHourly)
	}
}
开发者ID:jmptrader,项目名称:doctl,代码行数:30,代码来源:size.go

示例12: dropletList

func dropletList(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{}
	dropletList := []godo.Droplet{}

	for { // TODO make all optional
		dropletPage, resp, err := client.Droplets.List(opt)
		if err != nil {
			fmt.Printf("Unable to list Droplets: %s\n", err)
			os.Exit(1)
		}

		// append the current page's droplets to our list
		for _, d := range dropletPage {
			dropletList = append(dropletList, d)
		}

		// 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 {
			fmt.Printf("Unable to get pagination: %s\n", err)
			os.Exit(1)
		}

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

	cliOut := NewCLIOutput()
	defer cliOut.Flush()
	cliOut.Header("ID", "Name", "IP Address", "Status", "Memory", "Disk", "Region")
	for _, droplet := range dropletList {
		publicIP := PublicIPForDroplet(&droplet)

		cliOut.Writeln("%d\t%s\t%s\t%s\t%dMB\t%dGB\t%s\n",
			droplet.ID, droplet.Name, publicIP, droplet.Status, droplet.Memory, droplet.Disk, droplet.Region.Slug)
	}
}
开发者ID:jmptrader,项目名称:doctl,代码行数:52,代码来源:droplet.go

示例13: accountShow

func accountShow(ctx *cli.Context) {
	tokenSource := &TokenSource{
		AccessToken: APIKey,
	}
	oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
	client := godo.NewClient(oauthClient)

	account, _, err := client.Account.Get()
	if err != nil {
		log.Fatal(err)
	}

	WriteOutput(account)
}
开发者ID:phillbaker,项目名称:doctl,代码行数:14,代码来源:account.go

示例14: sshList

func sshList(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{}
	keyList := []godo.Key{}

	for {
		keyPage, resp, err := client.Keys.List(opt)
		if err != nil {
			fmt.Printf("Unable to list SSH Keys: %s\n", err)
			os.Exit(1)
		}

		// append the current page's droplets to our list
		for _, d := range keyPage {
			keyList = append(keyList, d)
		}

		// 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 {
			fmt.Printf("Unable to get pagination: %s\n", err)
			os.Exit(1)
		}

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

	cliOut := NewCLIOutput()
	defer cliOut.Flush()
	cliOut.Header("ID", "Name", "Fingerprint")
	for _, key := range keyList {
		cliOut.Writeln("%d\t%s\t%s\n", key.ID, key.Name, key.Fingerprint)
	}
}
开发者ID:jmptrader,项目名称:doctl,代码行数:49,代码来源:sshkey.go

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


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