本文整理汇总了Golang中github.com/grrtrr/exit.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var parentUUID string
var parentGroup = flag.String("g", "", "UUID or Name (if unique and -l present) of the parent Hardware Group")
var location = flag.String("l", "", "Data centre location to use for resolving -g <Group-Name>")
var desc = flag.String("t", "", "Textual description of the new group")
var acctAlias = flag.String("a", "", "Account alias to use")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <New Group Name>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *parentGroup == "" {
flag.Usage()
os.Exit(1)
}
/* parentGroup may be hex uuid or group name */
if _, err := hex.DecodeString(*parentGroup); err == nil {
parentUUID = *parentGroup
} else if *location == "" {
exit.Errorf("Using -g <Group-Name> requires -l <Location> to be set")
}
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)
}
if parentUUID == "" {
if group, err := client.GetGroupByName(*parentGroup, *location, *acctAlias); err != nil {
exit.Errorf("Failed to resolve group name %q: %s", *parentGroup, err)
} else if group == nil {
exit.Errorf("No group named %q was found on %s", *parentGroup, *location)
} else {
parentUUID = group.UUID
}
}
g, err := client.CreateHardwareGroup(*acctAlias, parentUUID, flag.Arg(0), *desc)
if err != nil {
exit.Fatalf("Failed to create hardware group %q: %s", flag.Arg(0), err)
}
fmt.Println("New Group: ", g.Name)
fmt.Println("UUID: ", g.UUID)
}
示例2: main
func main() {
var location = flag.String("l", "", "The location of the deployment to retrieve status for (required)")
var pollIntvl = flag.Int("i", 1, "Poll interval in seconds (to monitor progress")
var acctAlias = flag.String("a", "", "Account alias to use")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Request-ID>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *location == "" {
flag.Usage()
os.Exit(1)
}
reqId, err := strconv.ParseUint(flag.Arg(0), 10, 32)
if err != nil {
exit.Errorf("Invalid Request ID %q: %s", flag.Arg(0), err)
}
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)
}
err = client.PollDeploymentStatus(int(reqId), *location, *acctAlias, *pollIntvl)
if err != nil {
exit.Fatalf("Failed to poll status of request ID %d: %s", reqId, err)
}
}
示例3: main
func main() {
var location = flag.String("l", "", "Alias of the data centre the server resides in")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <IP Address>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *location == "" {
flag.Usage()
os.Exit(1)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
iad, err := client.GetNetworkDetailsByIp(flag.Arg(0), *location)
if err != nil {
exit.Fatalf("failed to look up %s: %s", flag.Arg(0), err)
} else if iad == nil {
exit.Errorf("No match found for %s in %s", flag.Arg(0), *location)
}
// The 'Server' field is not necessarily filled in, hence we need to test here.
if iad.Server != "" {
fmt.Printf("%s is used by %s.\n", iad.Address, iad.Server)
} else {
fmt.Printf("%s is in %s use in %s, but the server name is not disclosed.\n", iad.Address, iad.Type, *location)
}
}
示例4: 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)
}
示例5: main
func main() {
var parentGroup = flag.String("g", "", "UUID or Name (if unique and -l present) of the parent Hardware Group")
var location = flag.String("l", "", "Data centre location to use for resolving -g <Group-Name>")
var desc = flag.String("t", "", "Textual description of the new group")
var parentUUID string
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <New Group Name>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *parentGroup == "" {
flag.Usage()
os.Exit(1)
}
/* parentGroup may be hex uuid or group name */
if _, err := hex.DecodeString(*parentGroup); err == nil {
parentUUID = *parentGroup
} else if *location == "" {
exit.Errorf("Using -g <Group-Name> requires -l <Location> to be set")
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
if parentUUID == "" { /* resolve group name */
if group, err := client.GetGroupByName(*parentGroup, *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", *parentGroup, err)
} else if group == nil {
exit.Errorf("No group named %q was found in %s", *parentGroup, *location)
} else {
parentUUID = group.Id
}
}
g, err := client.CreateGroup(flag.Arg(0), parentUUID, *desc, []clcv2.SimpleCustomField{})
if err != nil {
exit.Fatalf("failed to create hardware group %q: %s", flag.Arg(0), err)
}
fmt.Println("New Group: ", g.Name)
fmt.Println("UUID: ", g.Id)
}
示例6: main
func main() {
// Allow two types of ID: (a) <major>:<minor> syntax, (b) <minor> syntax
var reMajMin = regexp.MustCompile(`^\d+:\d+$`)
var reMin = regexp.MustCompile(`^\d+$`)
var ids []string
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Server Name> <diskId> [<diskId> ...]\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() < 2 {
flag.Usage()
os.Exit(1)
}
for i := 1; i < flag.NArg(); i++ {
if reMajMin.MatchString(flag.Arg(i)) {
ids = append(ids, flag.Arg(i))
} else if reMin.MatchString(flag.Arg(i)) {
ids = append(ids, fmt.Sprintf("0:%s", flag.Arg(i)))
} else {
exit.Errorf("invalid disk ID %q", flag.Arg(i))
}
}
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, 0)
for i := range server.Details.Disks {
if inStringArray(server.Details.Disks[i].Id, ids...) {
fmt.Printf("Deleting disk %s (%d GB) ...\n", server.Details.Disks[i].Id, server.Details.Disks[i].SizeGB)
} else {
disks = append(disks, clcv2.ServerAdditionalDisk{
Id: server.Details.Disks[i].Id,
SizeGB: server.Details.Disks[i].SizeGB,
})
}
}
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 updating the disks on %s: %s", flag.Arg(0), reqID)
client.PollStatus(reqID, 5*time.Second)
}
示例7: main
func main() {
var hwGroup = flag.String("g", "", "UUID or name (if unique) of the HW group to restore this group to")
var location = flag.String("l", "", "Data centre alias (to resolve group and/or network ID)")
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 || *hwGroup == "" {
flag.Usage()
os.Exit(1)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
/* hwGroup may be hex uuid or group name */
if _, err := hex.DecodeString(*hwGroup); err == nil {
/* already looks like a HEX ID */
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if not using a HW Group UUID (%s)", *hwGroup)
} else {
fmt.Printf("Resolving ID of Hardware Group %q ...\n", *hwGroup)
if group, err := client.GetGroupByName(*hwGroup, *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", *hwGroup, err)
} else if group == nil {
exit.Errorf("No group named %q was found in %s", *hwGroup, *location)
} else {
*hwGroup = group.Id
}
}
statusId, err := client.RestoreGroup(flag.Arg(0), *hwGroup)
if err != nil {
exit.Fatalf("failed to restore group %s: %s", flag.Arg(0), err)
}
fmt.Println("Request ID for restoring group:", statusId)
}
示例8: main
func main() {
var uuid string /* UUID of the HW group to delete */
var location = flag.String("l", "", "Data center location if using HW Group-Name")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <HW Group-Name or UUID>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
os.Exit(1)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
/* If the first argument decodes as a hex value, assume it is a Hardware Group UUID */
if _, err := hex.DecodeString(flag.Arg(0)); err == nil {
uuid = flag.Arg(0)
} else if *location == "" {
exit.Errorf("Need a location (-l argument) when not using a HW Group UUID")
} else {
fmt.Printf("Resolving group UUID of %s in %s ...\n", flag.Arg(0), *location)
if grp, err := client.GetGroupByName(flag.Arg(0), *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", flag.Arg(0), err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", flag.Arg(0), *location)
} else {
uuid = grp.Id
}
}
reqId, err := client.DeleteGroup(uuid)
if err != nil {
exit.Fatalf("failed to delete hardware group: %s", err)
}
fmt.Printf("Status ID for group deletion: %s\n", reqId)
}
示例9: main
func main() {
var (
query = flag.String("q", "none", "Filter IP addresses; one of 'none', 'claimed', 'free', or 'all'")
location = flag.String("l", os.Getenv("CLC_LOCATION"), "Data centre alias (needed to resolve IDs)")
simple = flag.Bool("simple", false, "Use simple (debugging) output format")
)
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] -l <Location> <Network-ID (hex)>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
/* Location is required (despite hex id), an empty location leads to a "404 Not Found" response. */
if flag.NArg() != 1 || *location == "" {
flag.Usage()
os.Exit(1)
} else if !inStringArray(*query, "none", "claimed", "free", "all") {
exit.Errorf("Invalid IP query %q. Try -h")
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
details, err := client.GetNetworkDetails(*location, flag.Arg(0), *query)
if err != nil {
exit.Fatalf("failed to query network details of %s: %s", flag.Arg(0), err)
}
if *simple {
pretty.Println(details)
} else {
fmt.Printf("Details of %s (%s):\n", details.Name, details.Description)
fmt.Printf("CIDR: %s\n", details.Cidr)
fmt.Printf("Gateway: %s\n", details.Gateway)
fmt.Printf("Type: %s\n", details.Type)
fmt.Printf("VLAN: %d\n", details.Vlan)
if len(details.IpAddresses) > 0 {
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_RIGHT)
table.SetAutoWrapText(false)
table.SetHeader([]string{"Address", "Claimed", "Server", "Type"})
for _, i := range details.IpAddresses {
table.Append([]string{i.Address, fmt.Sprint(i.Claimed), i.Server, i.Type})
}
table.Render()
}
}
}
示例10: main
func main() {
var group = flag.String("g", "", "UUID or name of the new parent group")
var location = flag.String("l", "", "Location to use if -g refers to a Group-Name")
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 || *group == "" {
flag.Usage()
os.Exit(1)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
if _, err := hex.DecodeString(*group); err == nil {
/* Looks like a Group UUID */
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if -g (%s) is not a UUID", *group)
} else {
if grp, err := client.GetGroupByName(*group, *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", *group, err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", *group, *location)
} else {
*group = grp.Id
}
}
err = client.ServerSetGroup(flag.Arg(0), *group)
if err != nil {
exit.Fatalf("failed to change the parent group on %q: %s", flag.Arg(0), err)
}
fmt.Printf("Successfully changed the parent group of %s to %s.\n", flag.Arg(0), *group)
}
示例11: main
func main() {
var location = flag.String("l", "", "Location to use if using a Group-Name instead of a UUID")
var uuid string
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Group Name or UUID>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
os.Exit(1)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
if _, err := hex.DecodeString(flag.Arg(0)); err == nil {
uuid = flag.Arg(0)
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if not using Group UUID (%s)", flag.Arg(0))
} else {
if grp, err := client.GetGroupByName(flag.Arg(0), *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", flag.Arg(0), err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", flag.Arg(0), *location)
} else {
uuid = grp.Id
}
}
statusId, err := client.ArchiveGroup(uuid)
if err != nil {
exit.Fatalf("failed to archive group %s: %s", flag.Arg(0), err)
}
fmt.Println("Request ID for archiving group:", statusId)
}
示例12: main
func main() {
var group string /* UUID of the group to change */
var newName = flag.String("n", "", "New name for the group")
var location = flag.String("l", "", "Location to use if using a Group-Name instead of a UUID")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Group Name or UUID>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *newName == "" {
flag.Usage()
os.Exit(1)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
if _, err := hex.DecodeString(flag.Arg(0)); err == nil {
group = flag.Arg(0)
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if not using Group UUID (%s)", flag.Arg(0))
} else {
if grp, err := client.GetGroupByName(flag.Arg(0), *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", flag.Arg(0), err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", flag.Arg(0), *location)
} else {
group = grp.Id
}
}
if err = client.GroupSetName(group, *newName); err != nil {
exit.Fatalf("failed to change the name of %q: %s", flag.Arg(0), err)
}
fmt.Printf("Successfully changed the name of %s to %q.\n", flag.Arg(0), *newName)
}
示例13: CollapseIpRanges
// Collapse an unsorted array @in of IPv4 addresses into sorted ranges in @out.
func CollapseIpRanges(in []string) (out []string) {
var start, end, prev net.IP
var ips []net.IP
for _, ip_string := range in {
ip := net.ParseIP(ip_string)
if ip == nil {
exit.Errorf("Invalid IP address %q", ip_string)
}
ip = ip.To4()
if ip == nil {
exit.Errorf("Not an IPv4 address: %q", ip_string)
}
ips = append(ips, ip)
}
sort.Stable(byIPv4Address(ips))
for _, ip := range ips {
if prev != nil && reflect.DeepEqual(ip[:3], prev[:3]) && ip[3] == prev[3]+1 {
end = ip
} else {
if end != nil {
out = append(out, fmt.Sprintf("%s-%d", start, end[3]))
end = nil
} else if prev != nil {
out = append(out, prev.String())
}
start = ip
}
prev = ip
}
if end != nil {
out = append(out, fmt.Sprintf("%s-%d", start, end[3]))
}
return out
}
示例14: main
func main() {
var child string /* UUID of the group to relocate */
var parent = flag.String("g", "", "UUID or name of the new parent group")
var location = flag.String("l", "", "Location to use if using Group Name instead of UUID")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Group Name or UUID>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *parent == "" {
flag.Usage()
os.Exit(1)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
if _, err := hex.DecodeString(flag.Arg(0)); err == nil {
child = flag.Arg(0)
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if not using Group UUID (%s)", flag.Arg(0))
} else {
if grp, err := client.GetGroupByName(flag.Arg(0), *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", flag.Arg(0), err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", flag.Arg(0), *location)
} else {
child = grp.Id
}
}
if _, err := hex.DecodeString(*parent); err == nil {
/* Looks like a Group UUID */
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if parent (-g %s) is not a UUID", *parent)
} else {
if grp, err := client.GetGroupByName(*parent, *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", *parent, err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", *parent, *location)
} else {
*parent = grp.Id
}
}
err = client.GroupSetParent(child, *parent)
if err != nil {
exit.Fatalf("failed to change the parent group of %q: %s", flag.Arg(0), err)
}
fmt.Printf("Successfully changed the parent group of %s to %s.\n", flag.Arg(0), *parent)
}
示例15: main
func main() {
var acctAlias = flag.String("a", "", "Account alias of the account in question")
var location = flag.String("l", "", "Data center location of @Group-Name")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Group-Name>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *location == "" {
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)
}
groups, err := client.GetGroups(*location, *acctAlias)
if err != nil {
exit.Fatalf("Failed to obtain hardware groups: %s", err)
}
if len(groups) == 0 {
exit.Errorf("Empty result.")
}
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoWrapText(true)
table.SetHeader([]string{"Name", "UUID", "Parent UUID", "System Group?"})
for _, g := range groups {
if g.Name == flag.Arg(0) {
table.Append([]string{g.Name, g.UUID, g.ParentUUID, fmt.Sprint(g.IsSystemGroup)})
}
}
table.Render()
}