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


Golang exit.Fatalf函数代码示例

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


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

示例1: main

func main() {
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")
	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	locations, err := client.GetLocations()
	if err != nil {
		exit.Fatalf("Failed to list queue requests: %s", err)
	}

	if len(locations) == 0 {
		println("Empty result.")
	} else if *simple {
		for _, l := range locations {
			utils.PrintStruct(l)
		}
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoFormatHeaders(false)
		table.SetAlignment(tablewriter.ALIGN_LEFT)
		table.SetAutoWrapText(false)

		table.SetHeader([]string{"Alias", "Region"})
		for _, l := range locations {
			table.Append([]string{l.Alias, l.Region})
		}
		table.Render()
	}
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:35,代码来源:locations.go

示例2: main

func main() {
	var size = flag.Uint("size", 0, "New size of the disk in GB")
	// Allow the same ID types as in disk_remove.go
	var reMajMin = regexp.MustCompile(`^\d+:\d+$`)
	var reMin = regexp.MustCompile(`^\d+$`)
	var id string

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Server-Name>  <Disk-ID>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 2 || *size == 0 {
		flag.Usage()
		os.Exit(1)
	} else if reMajMin.MatchString(flag.Arg(1)) {
		id = flag.Arg(1)
	} else if reMin.MatchString(flag.Arg(1)) {
		id = fmt.Sprintf("0:%s", flag.Arg(1))
	} else {
		exit.Errorf("invalid disk ID %q", flag.Arg(1))
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	server, err := client.GetServer(flag.Arg(0))
	if err != nil {
		exit.Fatalf("failed to list details of server %q: %s", flag.Arg(0), err)
	}

	disks := make([]clcv2.ServerAdditionalDisk, len(server.Details.Disks))
	for i := range server.Details.Disks {
		disks[i] = clcv2.ServerAdditionalDisk{
			Id:     server.Details.Disks[i].Id,
			SizeGB: server.Details.Disks[i].SizeGB,
		}
		if disks[i].Id == id {
			// The API does not allow to reduce the size of an existing disk.
			if uint32(*size) <= disks[i].SizeGB {
				fmt.Printf("Disk %s size is already at %d GB.\n", id, disks[i].SizeGB)
				os.Exit(0)
			}
			fmt.Printf("Changing disk %s size from %d to %d GB ...\n",
				id, disks[i].SizeGB, *size)
			disks[i].SizeGB = uint32(*size)
		}
	}

	reqID, err := client.ServerSetDisks(flag.Arg(0), disks)
	if err != nil {
		exit.Fatalf("failed to update the disk configuration on %q: %s", flag.Arg(0), err)
	}

	log.Printf("Status Id for resizing the disk on %s: %s", flag.Arg(0), reqID)
	client.PollStatus(reqID, 10*time.Second)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:60,代码来源:disk_resize.go

示例3: main

func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var busId = flag.String("bus", "", "The SCSI bus ID of the disk")
	var devId = flag.String("dev", "", "The SCSI device ID of the disk")
	var force = flag.Bool("force", false, "Override safety checks required for primary/OS disks")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *busId == "" || *devId == "" {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.DeleteDisk(flag.Arg(0), *acctAlias, *busId, *devId, *force)
	if err != nil {
		exit.Fatalf("Failed to delete disk on %s: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for server disk deletion:", reqId)
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:31,代码来源:disk_delete.go

示例4: main

func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <HW Group UUID>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.ArchiveHardwareGroup(flag.Arg(0), *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to archive Hardware Group %s: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for group archival:", reqId)
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:28,代码来源:archive.go

示例5: main

func main() {
	var acctAlias = flag.String("a", "", "Account alias of the account that owns the servers")
	var location = flag.String("l", "", "The data center location")
	var hwGrpUUID = flag.String("u", "", "UUID of the Hardware Group")
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  [<location>]\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 0 && *location != "" {
		flag.Usage()
		os.Exit(1)
	} else if flag.NArg() == 1 {
		*location = flag.Arg(0)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	servers, err := client.GetAllServers(*acctAlias, *hwGrpUUID, *location)
	if err != nil {
		exit.Fatalf("Failed to list all servers: %s", err)
	}

	if len(servers) == 0 {
		println("Empty result.")
	} else if *simple {
		for _, s := range servers {
			utils.PrintStruct(s)
		}
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoFormatHeaders(false)
		table.SetAlignment(tablewriter.ALIGN_LEFT)
		table.SetAutoWrapText(true)

		table.SetHeader([]string{
			"Name", "Description",
			"#CPU", "#Disk", "Disk",
			"OS", "IP", "Power", "Who modified", "Modified date",
		})
		for _, s := range servers {
			table.Append([]string{
				s.Name, s.Description,
				fmt.Sprint(s.Cpu), fmt.Sprint(s.DiskCount), fmt.Sprint(s.TotalDiskSpaceGB),
				fmt.Sprintf("%25.25s", s.OperatingSystem), s.IPAddress,
				s.PowerState, fmt.Sprintf("%12.12s", s.ModifiedBy),
				s.DateModified.Format("Jan _2/06 15:04"),
			})
		}
		table.Render()
	}
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:60,代码来源:all_servers.go

示例6: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s <Account-Alias>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(0)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	acctDetails, err := client.GetAccountDetails(flag.Arg(0))
	if err != nil {
		exit.Fatalf("Failed to obtain account details of %s: %s", flag.Arg(0), err)
	}

	utils.PrintStruct(acctDetails)
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:26,代码来源:details.go

示例7: addRawDisk

// addRawDisk adds storage in form of a raw disk to a server
// @client:   authenticated CLCv2 client
// @servname: server name
// @diskGB:   amount of storage in GB to add to @servname
func addRawDisk(client *clcv2.CLIClient, servname string, diskGB uint32) (statusId string) {
	/* First get the list of disks */
	server, err := client.GetServer(servname)
	if err != nil {
		exit.Fatalf("failed to list details of server %q: %s", servname, err)
	}

	disks := make([]clcv2.ServerAdditionalDisk, len(server.Details.Disks))
	for i := range server.Details.Disks {
		disks[i] = clcv2.ServerAdditionalDisk{
			Id:     server.Details.Disks[i].Id,
			SizeGB: server.Details.Disks[i].SizeGB,
		}
	}

	statusId, err = client.ServerSetDisks(servname, append(disks,
		clcv2.ServerAdditionalDisk{
			SizeGB: diskGB,
			Type:   "raw",
		}))
	if err != nil {
		exit.Fatalf("failed to update the disk configuration on %q: %s", servname, err)
	}
	return statusId
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:29,代码来源:clc_action.go

示例8: main

func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")

	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	customFields, err := client.GetCustomFields(*acctAlias)
	if err != nil {
		exit.Fatalf("Failed to obtain Custom Fields of %s: %s", *acctAlias, err)
	}

	if len(customFields) == 0 {
		println("Empty result.")
	} else {
		for _, cf := range customFields {
			utils.PrintStruct(cf)
		}
	}
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:25,代码来源:custom_fields.go

示例9: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Location>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}
	flag.Parse()

	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	rootGroup, err := client.GetRootGroup(flag.Arg(0))
	if err != nil {
		exit.Fatalf("Failed to list root group: %s", err)
	}

	fmt.Println("Location:   ", flag.Arg(0))
	fmt.Println("Root Group: ", rootGroup.Name)
	fmt.Println("UUID:       ", rootGroup.UUID)
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:28,代码来源:rootGroup.go

示例10: main

func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var hwGrpUUID = flag.String("u", "", "UUID of the Hardware Group to restore the server to")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.RestoreServer(flag.Arg(0), *acctAlias, *hwGrpUUID)
	if err != nil {
		exit.Fatalf("Failed to restore server %s: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for restoring server:", reqId)
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:29,代码来源:restore.go

示例11: main

func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var busId = flag.String("bus", "", "The SCSI bus ID of the disk")
	var devId = flag.String("dev", "", "The SCSI device ID of the disk")
	var newSize = flag.Int("s", 0, "The expanded size of the disk")
	var expand = flag.Bool("e", false, "Expand the filesystem on the disk after the resize")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *busId == "" || *devId == "" {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.ResizeDisk(flag.Arg(0), *acctAlias, *busId, *devId, *newSize, *expand)
	if err != nil {
		exit.Fatalf("Failed to resize disk on %s: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for resizing server disk:", reqId)
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:32,代码来源:disk_resize.go

示例12: main

func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var maintenance = flag.Bool("m", false, "Turn maintenance mode on (-m) or off (-m=false)")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <HW Group UUID>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.HardwareGroupMaintenance(*maintenance, flag.Arg(0), *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to modify maintenance mode: %s", err)
	}

	fmt.Println("Request ID for group maintenance status change:", reqId)
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:29,代码来源:maintenance.go

示例13: main

func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")

	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	acctSummary, err := client.GetAccountSummary(*acctAlias)
	if err != nil {
		exit.Fatalf("Failed to obtain account billing summary of %s: %s", *acctAlias, err)
	}

	if *simple {
		utils.PrintStruct(acctSummary)
	} else {
		fmt.Printf("Total charges during this hour:     $%.2f\n", acctSummary.CurrentHour)
		fmt.Printf("Total charges during previous hour: $%.2f\n", acctSummary.PreviousHour)
		fmt.Printf("Total hourly charges this month:    $%.2f\n", acctSummary.MonthToDate)
		fmt.Printf("Total one-time charges this month:  $%.2f\n", acctSummary.OneTimeCharges)
		fmt.Printf("Total overall charges this month:   $%.2f\n", acctSummary.MonthToDateTotal)
		fmt.Printf("Corresponding monthly estimate:     $%.2f\n", acctSummary.MonthlyEstimate)

	}
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:30,代码来源:account_summary.go

示例14: main

func main() {
	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	accts, err := client.GetAccounts()
	if err != nil {
		exit.Fatalf("Failed to obtain account list: %s", err)
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetAutoFormatHeaders(false)
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.SetAutoWrapText(true)

	table.SetHeader([]string{"Account", "Parent", "Location", "Business Name"})
	for _, a := range accts {
		var acct = a.AccountAlias

		if !a.IsActive {
			acct += " (INACTIVE)"
		}
		table.Append([]string{acct, a.ParentAlias, a.Location, a.BusinessName})
	}
	table.Render()
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:31,代码来源:list.go

示例15: main

func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var password = flag.String("pass", "", "Administrator/root password for the server to convert")
	var templAlias = flag.String("alias", "TEMPL", "The alias for the Template to create")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *password == "" || *templAlias == "" {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.ConvertServerToTemplate(flag.Arg(0), *password, *templAlias, *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to convert %s into a template: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for converting server:", reqId)
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:30,代码来源:template_from_server.go


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