本文整理匯總了Golang中github.com/dynport/gocli.NewTable函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewTable函數的具體用法?Golang NewTable怎麽用?Golang NewTable使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewTable函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (a *DescribeInstances) Run() error {
log.Print("describing ec2 instances")
instances, e := client().DescribeInstances()
if e != nil {
return e
}
if a.Detailed {
for _, i := range instances {
table := gocli.NewTable()
table.Add(i.InstanceId, "Name", i.Name())
table.Add(i.InstanceId, "ImageId", i.ImageId)
table.Add(i.InstanceId, "InstanceType", i.InstanceType)
table.Add(i.InstanceId, "InstanceStateName", i.InstanceStateName)
table.Add(i.InstanceId, "Availability Zone", i.PlacementAvailabilityZone)
table.Add(i.InstanceId, "KeyName", i.KeyName)
table.Add(i.InstanceId, "IpAddress", i.IpAddress)
table.Add(i.InstanceId, "PrivateIpAddress", i.PrivateIpAddress)
table.Add(i.InstanceId, "LaunchTime", i.LaunchTime.Format("2006-01-02T15:04:05"))
table.Add(i.InstanceId, "VpcId", i.VpcId)
table.Add(i.InstanceId, "MonitoringState", i.MonitoringState)
table.Add(i.InstanceId, "SubnetId", i.SubnetId)
for _, group := range i.SecurityGroups {
table.Add(i.InstanceId, "SecurityGroup", group.GroupId)
}
for _, tag := range i.Tags {
table.Add(i.InstanceId, "Tag", tag.Key, tag.Value)
}
fmt.Println(table)
}
return nil
}
table := gocli.NewTable()
table.Add("id", "image", "name", "state", "type", "private_ip", "ip", "az", "launched")
for _, i := range instances {
sgs := []string{}
if i.InstanceStateName != "running" {
continue
}
for _, g := range i.SecurityGroups {
sgs = append(sgs, g.GroupId)
}
table.Add(
i.InstanceId,
i.ImageId,
i.Name(),
i.InstanceStateName,
i.InstanceType,
i.PrivateIpAddress,
i.IpAddress,
i.PlacementAvailabilityZone,
i.LaunchTime.Format("2006-01-02T15:04"),
)
}
fmt.Println(table)
return nil
}
示例2: printServer
func printServer(server *jiffybox.Server) {
table := gocli.NewTable()
table.Add("Id", server.Id)
table.Add("Name", server.Name)
table.Add("Status", server.Status)
table.Add("Created", server.CreatedAt().Format(TIME_FORMAT))
table.Add("Host", server.Host)
table.Add("Running", server.Running)
table.Add("RecoverymodeActive", server.RecoverymodeActive)
table.Add("Plan", server.Plan.Id)
table.Add("Cpu", server.Plan.Cpus)
table.Add("RAM", server.Plan.RamInMB)
table.Add("IsBeingCopied", server.IsBeingCopied)
table.Add("ManualBackupRunning", server.ManualBackupRunning)
if server.ActiveProfile != nil {
table.Add("Profile Name", server.ActiveProfile.Name)
table.Add("Profile Kernel", server.ActiveProfile.Kernel)
}
i := 0
for k, v := range server.Ips {
key := ""
if i == 0 {
key = "Ips"
i++
}
table.Add(key, k+": "+strings.Join(v, ", "))
}
fmt.Println(table)
}
示例3: Run
func (r *route53ListResourceRecordSet) Run() error {
client := route53.NewFromEnv()
rrsets, e := client.ListResourceRecordSets(r.HostedZone)
if e != nil {
return e
}
table := gocli.NewTable()
table.Add("name", "type", "ttl", "weight", "id", "hc id", "value")
maxLen := 64
for _, rrs := range rrsets {
weight := ""
if rrs.Weight > 0 {
weight = fmt.Sprintf("%d", rrs.Weight)
}
col := []string{
rrs.Name, rrs.Type, fmt.Sprintf("%d", rrs.TTL), rrs.SetIdentifier, weight, rrs.HealthCheckId,
}
for i, record := range rrs.ResourceRecords {
v := record.Value
if len(v) > maxLen {
v = v[0:maxLen]
}
if i == 0 {
col = append(col, v)
table.AddStrings(col)
} else {
table.Add("", "", "", "", "", "", v)
}
}
}
fmt.Println(table)
return nil
}
示例4: Compare
func Compare() error {
table := gocli.NewTable()
for _, plan := range digitalocean.Plans {
table.Add(plan.Cores, fmt.Sprintf("%.1f GB", float64(plan.MemoryInMB)/1024.0))
}
pricing, e := aws.LinuxOnDemand()
if e != nil {
return e
}
counts := map[string]int{}
for _, region := range pricing.Config.Regions {
for _, typ := range region.InstanceTypes {
for _, size := range typ.Sizes {
for _, vc := range size.ValueColumns {
counts[size.Size]++
table.Add(region.Region, typ.Type, size.Size, vc.Name, vc.Prices["USD"])
}
}
}
}
fmt.Println(table)
fmt.Println(counts)
return nil
}
示例5: ListDropletsAction
func ListDropletsAction() (e error) {
logger.Debug("listing droplets")
droplets, e := CurrentAccount().Droplets()
if e != nil {
return e
}
if _, e := CurrentAccount().CachedSizes(); e != nil {
return e
}
table := gocli.NewTable()
if len(droplets) == 0 {
table.Add("no droplets found")
} else {
table.Add("Id", "Created", "Status", "Locked", "Name", "IPAddress", "Region", "Size", "Image")
for _, droplet := range droplets {
table.Add(
strconv.Itoa(droplet.Id),
droplet.CreatedAt.Format("2006-01-02T15:04"),
droplet.Status,
strconv.FormatBool(droplet.Locked),
droplet.Name,
droplet.IpAddress,
fmt.Sprintf("%s (%d)", CurrentAccount().RegionName(droplet.RegionId), droplet.RegionId),
fmt.Sprintf("%s (%d)", CurrentAccount().SizeName(droplet.SizeId), droplet.SizeId),
fmt.Sprintf("%s (%d)", CurrentAccount().ImageName(droplet.ImageId), droplet.ImageId),
)
}
}
fmt.Fprintln(os.Stdout, table.String())
return nil
}
示例6: Run
func (a *ParametersDescribe) Run() error {
client := cloudformation.NewFromEnv()
tpl := cloudformation.DescribeStacks{
StackName: a.Name,
}
rsp, e := tpl.Execute(client)
if e != nil {
return e
}
stacks := rsp.DescribeStacksResult.Stacks
if len(stacks) != 1 {
return fmt.Errorf("expected 1 stack for %q, got %d", a.Name, len(stacks))
}
stack := stacks[0]
t := gocli.NewTable()
for _, p := range stack.Parameters {
value := p.ParameterValue
if len(value) > 64 && !a.Full {
value = value[0:64] + "... (truncated)"
}
t.Add(p.ParameterKey, value)
}
fmt.Println(t)
return nil
}
示例7: Run
func (l *ListGists) Run() error {
rsp, e := authenticatedRequest("GET", urlRoot+"/gists", nil)
if e != nil {
return e
}
defer rsp.Body.Close()
gists := []*Gist{}
e = json.NewDecoder(rsp.Body).Decode(&gists)
if e != nil {
return e
}
t := gocli.NewTable()
for _, g := range gists {
name := ""
if len(g.Files) > 0 {
for n := range g.Files {
name = n
break
}
}
if g.Public || !l.Public {
t.Add(g.CreatedAt.Local().Format(time.RFC3339), g.Id, name, g.Description)
}
}
io.WriteString(os.Stdout, t.String()+"\n")
return nil
}
示例8: Run
func (act *list) Run() error {
resp, err := newClient().DescribeDBSnapshots(&rds.DescribeDBSnapshotsInput{DBInstanceIdentifier: &act.InstanceId})
if err != nil {
return err
}
snapshots := resp.DBSnapshots
logger.Printf("found %d snapshots", len(snapshots))
table := gocli.NewTable()
for i := range snapshots {
t := ""
if v := snapshots[i].SnapshotCreateTime; v != nil {
t = v.UTC().Format("2006-01-02 15:04:05")
}
table.Add(
p2s(snapshots[i].DBInstanceIdentifier),
p2s(snapshots[i].DBSnapshotIdentifier),
p2s(snapshots[i].Status),
p2i64(snapshots[i].AllocatedStorage),
p2s(snapshots[i].Engine),
p2s(snapshots[i].EngineVersion),
t,
)
}
fmt.Println(table)
return nil
}
示例9: Run
func (a *nodesLS) Run() error {
h := a.Host
if !strings.HasPrefix(h, "http") {
h = "http://" + h
}
rsp, err := http.Get(h + "/_nodes/stats")
if err != nil {
return err
}
defer rsp.Body.Close()
if rsp.Status[0] != '2' {
b, _ := ioutil.ReadAll(rsp.Body)
return fmt.Errorf("got status %s but expected 2x. body=%s", rsp.Status, string(b))
}
var r *nodeStatsResponse
if err := json.NewDecoder(rsp.Body).Decode(&r); err != nil {
return err
}
t := gocli.NewTable()
list := NodeStats{}
for _, n := range r.Nodes {
list = append(list, n)
}
sort.Sort(list)
t.Add("name", "host", "address", "load5", "cpu sys", "cpu user", "cpu idle", "mem used")
for _, n := range list {
load5 := ""
if len(n.OS.LoadAverage) > 0 {
load5 = fmt.Sprintf("%.2f", n.OS.LoadAverage[0])
}
t.Add(n.Name, n.Host, n.TransportAddress, load5, n.OS.CPU.Sys, n.OS.CPU.User, n.OS.CPU.Idle, n.OS.Mem.UsedPercent)
}
fmt.Println(t)
return nil
}
示例10: DescribeSecurityGroups
func DescribeSecurityGroups() error {
groups, e := client().DescribeSecurityGroups(nil)
if e != nil {
return e
}
table := gocli.NewTable()
for _, group := range groups {
table.Add(group.GroupId, "", "", group.GroupName)
for _, perm := range group.IpPermissions {
ports := ""
if perm.FromPort > 0 {
if perm.FromPort == perm.ToPort {
ports += fmt.Sprintf("%d", perm.FromPort)
} else {
ports += fmt.Sprintf("%d-%d", perm.FromPort, perm.ToPort)
}
}
groups := []string{}
for _, group := range perm.Groups {
groups = append(groups, group.GroupId)
}
if len(groups) > 0 {
table.Add("", perm.IpProtocol, ports, strings.Join(groups, ","))
}
if len(perm.IpRanges) > 0 {
table.Add("", perm.IpProtocol, ports, strings.Join(perm.IpRanges, ","))
}
}
}
fmt.Print(table)
return nil
}
示例11: Run
func (r *dropletsList) Run() error {
cl, e := client()
if e != nil {
return e
}
rsp, e := cl.Droplets()
if e != nil {
return e
}
t := gocli.NewTable()
t.Add("Id", "Status", "Ip", "Name", "Region", "Size", "ImageId:ImageName (ImageSlug)", "CreatedAt")
for _, d := range rsp.Droplets {
imageName := fmt.Sprintf("%d:%s", d.Image.Id, d.Image.Name)
if d.Image.Slug != "" {
imageName += " (" + d.Image.Slug + ")"
}
ip := ""
if len(d.Networks.V4) > 0 {
ip = d.Networks.V4[0].IpAddress
}
t.Add(d.Id, d.Status, ip, d.Name, d.Region.Slug, d.Size.Slug, imageName, d.CreatedAt.Format("2006-01-02T15:04:05"))
}
fmt.Println(t)
return nil
}
示例12: VersionAction
func VersionAction(args *gocli.Args) error {
table := gocli.NewTable()
table.Add("Version", digo.VERSION)
if len(digo.GITCOMMIT) > 0 {
table.Add("Revision", digo.GITCOMMIT)
}
fmt.Printf(table.String())
return nil
}
示例13: printConfigsDetailed
func printConfigsDetailed(regionName string, typ string, priceMapping map[string]pricing.PriceList, configs pricing.InstanceTypeConfigs) {
table := gocli.NewTable()
for _, config := range configs {
table.Add("Type", config.Name)
table.Add("CPUs", config.Cpus)
table.Add("Storage", config.Storage)
table.Add("-------", "")
}
fmt.Println(table)
}
示例14: Run
func (r *StackDescription) Run() error {
client := cloudformation.NewFromEnv()
rsp, e := client.DescribeStacks(&cloudformation.DescribeStacksParameters{
StackName: r.Name,
})
if e != nil {
return e
}
if rsp.DescribeStacksResult == nil || len(rsp.DescribeStacksResult.Stacks) == 0 {
return nil
}
s := rsp.DescribeStacksResult.Stacks[0]
t := gocli.NewTable()
t.Add("name", s.StackName)
t.Add("created", s.CreationTime)
t.Add("state", s.StackStatus)
if len(s.Parameters) > 0 {
t := gocli.NewTable()
fmt.Println("Parameters:")
for _, p := range s.Parameters {
t.Add(p.ParameterKey, p.ParameterValue)
}
fmt.Println(t)
} else {
fmt.Println("Parameters: none")
}
if len(s.Outputs) > 0 {
t := gocli.NewTable()
fmt.Println("Outputs:")
for _, p := range s.Outputs {
t.Add(p.OutputKey, p.OutputValue)
}
fmt.Println(t)
} else {
fmt.Println("Outputs: none")
}
fmt.Println(t)
return nil
}
示例15: DescribeKeyPairs
func DescribeKeyPairs() error {
pairs, e := client().DescribeKeyPairs()
if e != nil {
return e
}
table := gocli.NewTable()
for _, pair := range pairs {
table.Add(pair.KeyName, pair.KeyFingerprint)
}
fmt.Print(table)
return nil
}