本文整理匯總了Golang中github.com/olekukonko/tablewriter.NewWriter函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewWriter函數的具體用法?Golang NewWriter怎麽用?Golang NewWriter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewWriter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
var links = flag.Bool("l", false, "List the Link References as well")
flag.Parse()
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
datacenters, err := client.GetLocations()
if err != nil {
exit.Fatalf("failed to get datacenter information: %s", err)
}
if *links {
for _, ctr := range datacenters {
fmt.Println("\n", ctr.Name)
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoWrapText(false)
// See https://www.ctl.io/api-docs/v2/#getting-started-api-v20-links-framework
table.SetHeader([]string{"Rel", "Href", "Verbs"})
for _, link := range ctr.Links {
var verbs string
if len(link.Verbs) == 0 {
verbs = "GET"
} else {
verbs = strings.Join(link.Verbs, ", ")
}
table.Append([]string{link.Rel, link.Href, verbs})
}
table.Render()
}
} else {
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoWrapText(false)
table.SetHeader([]string{"Id", "Name"})
for _, ctr := range datacenters {
table.Append([]string{ctr.Id, ctr.Name})
}
table.Render()
}
}
示例2: actionStatus
func actionStatus(c *cli.Context) {
err, profile := loadProfile(c, true)
if err != nil {
panic(err)
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Id", "Name", "Cert", "Type", "URL"})
maxCacheAge := profile.MaxCacheAge
if c.GlobalBool("flushCache") == true {
maxCacheAge = 0
}
err, instances := getInstances(profile.Region, maxCacheAge, profile)
if err != nil {
panic(err)
}
for _, instance := range instances {
table.Append([]string{
instance.Id, instance.Name,
instance.CertName, instance.InstanceType,
instance.PublicDnsName,
})
}
table.Render()
}
示例3: PrintStruct
// Print (pointer) to struct as table, using key/type/value
func PrintStruct(in interface{}) {
t := reflect.TypeOf(in)
v := reflect.ValueOf(in)
if in == nil {
fmt.Println("nil")
return
}
if t.Kind() == reflect.Ptr {
t = t.Elem()
v = reflect.Indirect(v)
}
if t.Kind() != reflect.Struct {
panic(fmt.Errorf("Expected a struct, got %T", in))
}
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoWrapText(false)
table.SetHeader([]string{t.Name(), "Type", "Value"})
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
table.Append([]string{f.Name, f.Type.Name(), fmt.Sprintf("%v", v.Field(i))})
}
table.Render()
}
示例4: main
func main() {
kingpin.Parse()
client := rundeck.NewClientFromEnv()
top, err := client.GetHistory(*projectid)
if err != nil {
fmt.Printf("%s\n", err)
} else {
table := tablewriter.NewWriter(os.Stdout)
for _, data := range top.Events {
var job string
if data.Job != nil {
job = data.Job.ID
} else {
job = "<adhoc>"
}
table.SetHeader([]string{"Status", "Summary", "Start Time", "End Time", "S/F/T", "Job", "Execution", "User", "Project"})
table.Append([]string{
data.Status,
data.Summary,
data.StartTime,
data.EndTime,
fmt.Sprintf("%d/%d/%d", data.NodeSummary.Succeeded, data.NodeSummary.Failed, data.NodeSummary.Total),
job,
fmt.Sprintf("%d", data.Execution.ID),
data.User,
data.Project,
})
}
table.Render()
}
}
示例5: showImages
func showImages(images []shared.ImageInfo) error {
data := [][]string{}
for _, image := range images {
shortest := shortestAlias(image.Aliases)
if len(image.Aliases) > 1 {
shortest = fmt.Sprintf(gettext.Gettext("%s (%d more)"), shortest, len(image.Aliases)-1)
}
fp := image.Fingerprint[0:12]
public := gettext.Gettext("no")
description := findDescription(image.Properties)
if shared.InterfaceToBool(image.Public) {
public = gettext.Gettext("yes")
}
const layout = "Jan 2, 2006 at 3:04pm (MST)"
uploaded := time.Unix(image.UploadDate, 0).Format(layout)
arch, _ := shared.ArchitectureName(image.Architecture)
data = append(data, []string{shortest, fp, public, description, arch, uploaded})
}
table := tablewriter.NewWriter(os.Stdout)
table.SetColWidth(50)
table.SetHeader([]string{
gettext.Gettext("ALIAS"),
gettext.Gettext("FINGERPRINT"),
gettext.Gettext("PUBLIC"),
gettext.Gettext("DESCRIPTION"),
gettext.Gettext("ARCH"),
gettext.Gettext("UPLOAD DATE")})
sort.Sort(ByName(data))
table.AppendBulk(data)
table.Render()
return nil
}
示例6: main
func main() {
kingpin.Parse()
client := artifactory.NewClientFromEnv()
data, err := client.GetRepos(*kind)
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
} else {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Key",
"Type",
"Description",
"Url",
})
for _, r := range data {
table.Append([]string{
r.Key,
r.Rtype,
r.Description,
r.Url,
})
}
table.Render()
os.Exit(0)
}
}
示例7: showTable
func (this *Verify) showTable() {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"AppId", "PubSub Topic", "Desc", "Kafka Topic", "?"})
for _, t := range this.topics {
kafkaTopic := t.KafkaTopicName
if kafkaTopic == "" {
// try find its counterpart in raw kafka
var q *dbx.Query
if _, present := this.kafkaTopics[t.TopicName]; present {
kafkaTopic = "[" + t.TopicName + "]"
q = this.db.NewQuery(fmt.Sprintf("UPDATE topics SET KafkaTopicName='%s' WHERE TopicId=%s",
t.TopicName, t.TopicId))
this.Ui.Output(q.SQL())
}
if q != nil && this.confirmed {
_, err := q.Execute()
swallow(err)
}
}
problem := "N"
if _, present := this.problemeticTopics[kafkaTopic]; present {
problem = color.Yellow("Y")
}
table.Append([]string{t.AppId, t.TopicName, t.TopicIntro, kafkaTopic, problem})
}
table.Render()
}
示例8: CmdList
func CmdList(is ISites, iservices services.IServices) error {
serviceProxy, err := iservices.RetrieveByLabel("service_proxy")
if err != nil {
return err
}
sites, err := is.List(serviceProxy.ID)
if err != nil {
return err
}
if sites == nil || len(*sites) == 0 {
logrus.Println("No sites found")
return nil
}
svcs, err := iservices.List()
svcMap := map[string]string{}
for _, s := range *svcs {
svcMap[s.ID] = s.Label
}
data := [][]string{{"NAME", "CERT", "UPSTREAM SERVICE"}}
for _, s := range *sites {
data = append(data, []string{s.Name, s.Cert, svcMap[s.UpstreamService]})
}
table := tablewriter.NewWriter(logrus.StandardLogger().Out)
table.SetBorder(false)
table.SetRowLine(false)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.AppendBulk(data)
table.Render()
return nil
}
示例9: InspectGit
func InspectGit(root string) {
if _, err := os.Stat(root); err == nil {
fmt.Printf("Inspecting system for git repos at '%v'...\n", root)
gitRepos := make(map[string]GitRepo)
findGitRepositories(root, gitRepos)
if len(gitRepos) >= 0 {
keys := make([]string, len(gitRepos))
i := 0
for key := range gitRepos {
keys[i] = key
i++
}
sort.Strings(keys)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Branch", "Status", "Path"})
for i := range keys {
repo := gitRepos[keys[i]]
v := []string{repo.name, repo.branch, repo.status, repo.path}
table.Append(v)
}
table.Render()
} else {
fmt.Printf("No repos found")
}
} else {
if os.IsNotExist(err) {
fmt.Printf("Directory '%v' does not exist\n", root)
os.Exit(1)
}
}
}
示例10: WriteTable
func WriteTable(groups []*dal.PingGroup) {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Time",
"min",
"avg",
"max",
"std dev",
"Received",
"Lost",
})
table.SetBorder(false) // Set Border to false
table.SetAlignment(tablewriter.ALIGN_RIGHT)
for _, g := range groups {
row := []string{
fmt.Sprintf("%s", g.Start.In(time.Local).Format(tableTimeFmt)),
fmt.Sprintf("%.0f ms", g.MinTime),
fmt.Sprintf("%.0f ms", g.AvgTime),
fmt.Sprintf("%.0f ms", g.MaxTime),
fmt.Sprintf("%.0f ms", g.StdDev),
fmt.Sprintf("%d", g.Received),
fmt.Sprintf("%d", g.Timedout),
}
table.Append(row)
}
table.Render()
}
示例11: listCmd
func listCmd(c *cli.Context) {
data := [][]string{}
stackMap, err := stackManager.SearchContainers(c.String("if"), c.String("tf"), c.String("cf"))
if err != nil {
util.Log.Fatalln(err)
}
for stackKey, containers := range stackMap {
for _, c := range containers {
var ports string
for key, val := range c.PublicPorts() {
ports = ports + strconv.FormatInt(val, 10) + "->" + strconv.FormatInt(key, 10) + " "
}
data = append(data, []string{stackKey, c.ContainerSwarmNode(), c.ContainerName(), c.ContainerImageName(), c.ContainerState(), ports})
}
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Stack", "Node", "Name", "Image", "Status", "Ports"})
for _, v := range data {
table.Append(v)
}
table.Render()
}
示例12: renderInstanceTable
func renderInstanceTable(project_id string, instances []*compute.Instance) []byte {
var buf bytes.Buffer
table := tablewriter.NewWriter(&buf)
if project_id == "" {
table.SetHeader([]string{"PROJECT", "NAME", "ZONE", "MACHINE_TYPE", "INTERNAL_IP", "EXTERNAL_IP", "STATUS"})
} else {
table.SetHeader([]string{"NAME", "ZONE", "MACHINE_TYPE", "INTERNAL_IP", "EXTERNAL_IP", "STATUS"})
}
for _, ins := range instances {
p := (func(selflink string) string {
return strings.Split(strings.Split(selflink, "https://www.googleapis.com/compute/v1/projects/")[1], "/")[0]
})(ins.SelfLink)
zone := (func(a []string) string { return a[len(a)-1] })(strings.Split(ins.Zone, "/"))
machine_type := (func(a []string) string { return a[len(a)-1] })(strings.Split(ins.MachineType, "/"))
internal_ip := ins.NetworkInterfaces[0].NetworkIP
external_ip := ins.NetworkInterfaces[0].AccessConfigs[0].NatIP
var row []string
if project_id == "" {
row = []string{p, ins.Name, zone, machine_type, internal_ip, external_ip, ins.Status}
table.Append(row)
} else {
if project_id == p {
row = []string{ins.Name, zone, machine_type, internal_ip, external_ip, ins.Status}
table.Append(row)
}
}
}
table.Render()
return buf.Bytes()
}
示例13: main
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Account-Policy-ID>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
os.Exit(0)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
p, err := client.SBSgetPolicy(flag.Arg(0))
if err != nil {
exit.Fatalf("failed to list SBS account policy %s: %s", flag.Arg(0), err)
}
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoWrapText(false)
table.SetHeader([]string{"Name", "Policy ID", "OS", "Status", "Freq/h", "Ret/d", "Paths"})
table.Append([]string{p.Name, p.PolicyID, p.OsType, p.Status, fmt.Sprint(p.BackupIntervalHours),
fmt.Sprint(p.RetentionDays), strings.Join(p.Paths, ", ")})
table.Render()
}
示例14: Show
// Display project details
// http://docs.gemnasium.apiary.io/#get-%2Fprojects%2F%7Bslug%7D
func (p *Project) Show() error {
err := p.Fetch()
if err != nil {
return err
}
if config.RawFormat {
return nil
}
color.Println(fmt.Sprintf("%s: %s\n", p.Name, utils.StatusDots(p.Color)))
table := tablewriter.NewWriter(os.Stdout)
table.SetRowLine(true)
table.Append([]string{"Slug", p.Slug})
table.Append([]string{"Description", p.Description})
table.Append([]string{"Origin", p.Origin})
table.Append([]string{"Private", strconv.FormatBool(p.Private)})
table.Append([]string{"Monitored", strconv.FormatBool(p.Monitored)})
if !p.Monitored {
table.Append([]string{"Unmonitored reason", p.UnmonitoredReason})
}
table.Render()
return nil
}
示例15: prettyPrintTargets
// Given a list of KeyStores in order of listing preference, pretty-prints the
// root keys and then the signing keys.
func prettyPrintTargets(ts []*notaryclient.Target, writer io.Writer) {
if len(ts) == 0 {
writer.Write([]byte("\nNo targets present in this repository.\n\n"))
return
}
sort.Stable(targetsSorter(ts))
table := tablewriter.NewWriter(writer)
table.SetHeader([]string{"Name", "Digest", "Size (bytes)"})
table.SetBorder(false)
table.SetColumnSeparator(" ")
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("-")
table.SetAutoWrapText(false)
for _, t := range ts {
table.Append([]string{
t.Name,
hex.EncodeToString(t.Hashes["sha256"]),
fmt.Sprintf("%d", t.Length),
})
}
table.Render()
}