本文整理汇总了Golang中text/tabwriter.Writer.Write方法的典型用法代码示例。如果您正苦于以下问题:Golang Writer.Write方法的具体用法?Golang Writer.Write怎么用?Golang Writer.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类text/tabwriter.Writer
的用法示例。
在下文中一共展示了Writer.Write方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DescribeParameters
// DescribeParameters prints out information about the parameters of a template
func (d *TemplateDescriber) DescribeParameters(params []templateapi.Parameter, out *tabwriter.Writer) {
formatString(out, "Parameters", " ")
indent := " "
for _, p := range params {
formatString(out, indent+"Name", p.Name)
if len(p.DisplayName) > 0 {
formatString(out, indent+"Display Name", p.DisplayName)
}
if len(p.Description) > 0 {
formatString(out, indent+"Description", p.Description)
}
formatString(out, indent+"Required", p.Required)
if len(p.Generate) == 0 {
formatString(out, indent+"Value", p.Value)
continue
}
if len(p.Value) > 0 {
formatString(out, indent+"Value", p.Value)
formatString(out, indent+"Generated (ignored)", p.Generate)
formatString(out, indent+"From", p.From)
} else {
formatString(out, indent+"Generated", p.Generate)
formatString(out, indent+"From", p.From)
}
out.Write([]byte("\n"))
}
}
示例2: outputPluginResults
func outputPluginResults(w io.Writer, byt []byte) error {
var results []struct {
ID uint64
Name string
Description sql.NullString
Path string
DownloadCount uint64
Similarity float64
}
if err := json.Unmarshal(byt, &results); err != nil {
return err
}
writer := tabwriter.Writer{}
writer.Init(w, 0, 8, 1, '\t', 0)
_, err := writer.Write([]byte("NAME\tDESCRIPTION\tDOWNLOADS\n"))
if err != nil {
return err
}
for _, result := range results {
d := result.Description
if len(d.String) >= 30 {
d.String = d.String[:27] + "..."
}
_, err = writer.Write([]byte(fmt.Sprintf("%s\t%s\t%d\n",
result.Name, d.String, result.DownloadCount)))
if err != nil {
return err
}
}
return writer.Flush()
}
示例3: printAddons
func (c *AddonsGetCmd) printAddons(addons map[string]*kutil.ClusterAddon) error {
w := new(tabwriter.Writer)
var b bytes.Buffer
// Format in tab-separated columns with a tab stop of 8.
w.Init(os.Stdout, 0, 8, 0, '\t', tabwriter.StripEscape)
for _, n := range addons {
b.WriteByte(tabwriter.Escape)
b.WriteString(n.Name)
b.WriteByte(tabwriter.Escape)
b.WriteByte('\t')
b.WriteByte(tabwriter.Escape)
b.WriteString(n.Path)
b.WriteByte(tabwriter.Escape)
b.WriteByte('\n')
_, err := w.Write(b.Bytes())
if err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
b.Reset()
}
return w.Flush()
}
示例4: printNodesets
func (c *RollingUpdateClusterCmd) printNodesets(nodesets map[string]*kutil.Nodeset) error {
w := new(tabwriter.Writer)
var b bytes.Buffer
// Format in tab-separated columns with a tab stop of 8.
w.Init(os.Stdout, 0, 8, 0, '\t', tabwriter.StripEscape)
for _, n := range nodesets {
b.WriteByte(tabwriter.Escape)
b.WriteString(n.Name)
b.WriteByte(tabwriter.Escape)
b.WriteByte('\t')
b.WriteByte(tabwriter.Escape)
b.WriteString(n.Status)
b.WriteByte(tabwriter.Escape)
b.WriteByte('\t')
b.WriteByte(tabwriter.Escape)
b.WriteString(fmt.Sprintf("%d", len(n.NeedUpdate)))
b.WriteByte(tabwriter.Escape)
b.WriteByte('\t')
b.WriteByte(tabwriter.Escape)
b.WriteString(fmt.Sprintf("%d", len(n.Ready)))
b.WriteByte(tabwriter.Escape)
b.WriteByte('\n')
_, err := w.Write(b.Bytes())
if err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
b.Reset()
}
return w.Flush()
}
示例5: writeCluster
func writeCluster(w *tabwriter.Writer, cluster *libcarina.Cluster) (err error) {
s := strings.Join([]string{
cluster.ClusterName,
cluster.Flavor,
strconv.FormatInt(cluster.Nodes.Int64(), 10),
strconv.FormatBool(cluster.AutoScale),
cluster.Status,
}, "\t")
_, err = w.Write([]byte(s + "\n"))
return
}
示例6: writeClusterHeader
func writeClusterHeader(w *tabwriter.Writer) (err error) {
headerFields := []string{
"ClusterName",
"Flavor",
"Segments",
"AutoScale",
"Status",
}
s := strings.Join(headerFields, "\t")
_, err = w.Write([]byte(s + "\n"))
return err
}
示例7: NodeInfo
func (client *FSouza_NodeClient) NodeInfo(logger log.Log) {
images := client.Images()
if len(images) == 0 {
client.log.Message("|-- no image [" + client.node.MachineName() + "]")
} else {
client.log.Message("|-> Images")
w := new(tabwriter.Writer)
w.Init(client.log, 8, 12, 2, ' ', 0)
row := []string{
"|=",
"ID",
"RepoTags",
"Created",
// "Size",
// "VirtualSize",
// "ParentID",
// "RepoDigests",
// "Labels",
}
w.Write([]byte(strings.Join(row, "\t") + "\n"))
for _, image := range images {
row := []string{
"|-",
image.ID[:11],
strings.Join(image.RepoTags, ","),
strconv.FormatInt(image.Created, 10),
// strconv.FormatInt(image.Size, 10),
// strconv.FormatInt(image.VirtualSize, 10),
// image.ParentID,
// strings.Join(image.RepoDigests, "\n"),
// strings.Join(image.Labels, "\n"),
}
w.Write([]byte(strings.Join(row, "\t") + "\n"))
}
w.Flush()
}
}
示例8: processHeader
func processHeader(fc FileConfig, t *template.Template) {
// in file
iFile, err := os.Open(fc.Name)
if err != nil {
panic("Can't open " + fc.Name)
}
defer iFile.Close()
r := csv.NewReader(iFile)
r.Comma = '\t'
r.TrailingComma = true
record, err := r.Read()
fmt.Println("File: ", fc.Name)
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 0, '\t', tabwriter.Debug)
t.ExecuteTemplate(w, fc.TemplateName+"_H", makeTemplateContext(&record))
w.Write([]byte("\n"))
t.ExecuteTemplate(w, fc.TemplateName, makeTemplateContext(&record))
w.Flush()
fmt.Println("")
}
示例9: Run
func (c *GetSecretsCommand) Run() error {
var infos []*SecretInfo
{
caStore, err := rootCommand.CA()
if err != nil {
return err
}
ids, err := caStore.List()
if err != nil {
return fmt.Errorf("error listing CA store items %v", err)
}
for _, id := range ids {
info := &SecretInfo{
Id: id,
Type: "keypair",
}
infos = append(infos, info)
}
}
{
secretStore, err := rootCommand.Secrets()
if err != nil {
return err
}
ids, err := secretStore.ListSecrets()
if err != nil {
return fmt.Errorf("error listing secrets %v", err)
}
for _, id := range ids {
info := &SecretInfo{
Id: id,
Type: "secret",
}
infos = append(infos, info)
}
}
var b bytes.Buffer
w := new(tabwriter.Writer)
// Format in tab-separated columns with a tab stop of 8.
w.Init(os.Stdout, 0, 8, 0, '\t', tabwriter.StripEscape)
for _, info := range infos {
b.WriteByte(tabwriter.Escape)
b.WriteString(info.Type)
b.WriteByte(tabwriter.Escape)
b.WriteByte('\t')
b.WriteByte(tabwriter.Escape)
b.WriteString(info.Id)
b.WriteByte(tabwriter.Escape)
b.WriteByte('\n')
_, err := w.Write(b.Bytes())
if err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
b.Reset()
}
w.Flush()
return nil
}
示例10: WriteTable
func WriteTable(items interface{}, columns []string, fields interface{}) error {
itemsValue := reflect.ValueOf(items)
if itemsValue.Kind() != reflect.Slice {
glog.Fatal("unexpected kind for items in WriteTable: ", itemsValue.Kind())
}
fieldsValue := reflect.ValueOf(fields)
if fieldsValue.Kind() != reflect.Slice {
glog.Fatal("unexpected kind for fields in WriteTable: ", fieldsValue.Kind())
}
length := itemsValue.Len()
var b bytes.Buffer
w := new(tabwriter.Writer)
// Format in tab-separated columns with a tab stop of 8.
w.Init(os.Stdout, 0, 8, 0, '\t', tabwriter.StripEscape)
writeHeader := true
if writeHeader {
for i, c := range columns {
if i != 0 {
b.WriteByte('\t')
}
b.WriteByte(tabwriter.Escape)
b.WriteString(c)
b.WriteByte(tabwriter.Escape)
}
b.WriteByte('\n')
_, err := w.Write(b.Bytes())
if err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
b.Reset()
}
for i := 0; i < length; i++ {
item := itemsValue.Index(i)
for j := range columns {
if j != 0 {
b.WriteByte('\t')
}
fieldFunc := fieldsValue.Index(j)
var args []reflect.Value
args = append(args, item)
fvs := fieldFunc.Call(args)
fv := fvs[0]
s := fi.ValueAsString(fv)
b.WriteByte(tabwriter.Escape)
b.WriteString(s)
b.WriteByte(tabwriter.Escape)
}
b.WriteByte('\n')
_, err := w.Write(b.Bytes())
if err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
b.Reset()
}
w.Flush()
return nil
}
示例11: Run
func (c *DescribeSecretsCommand) Run() error {
w := new(tabwriter.Writer)
var b bytes.Buffer
// Format in tab-separated columns with a tab stop of 8.
w.Init(os.Stdout, 0, 8, 0, '\t', tabwriter.StripEscape)
{
caStore, err := rootCommand.CA()
if err != nil {
return err
}
ids, err := caStore.List()
if err != nil {
return fmt.Errorf("error listing CA store items %v", err)
}
for _, id := range ids {
cert, err := caStore.FindCert(id)
if err != nil {
return fmt.Errorf("error retrieving cert %q: %v", id, err)
}
key, err := caStore.FindPrivateKey(id)
if err != nil {
return fmt.Errorf("error retrieving private key %q: %v", id, err)
}
if key == nil && cert == nil {
continue
}
err = describeKeypair(id, cert, key, &b)
if err != nil {
return err
}
b.WriteString("\n")
_, err = w.Write(b.Bytes())
if err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
b.Reset()
}
}
{
secretStore, err := rootCommand.Secrets()
if err != nil {
return err
}
ids, err := secretStore.ListSecrets()
if err != nil {
return fmt.Errorf("error listing secrets %v", err)
}
for _, id := range ids {
secret, err := secretStore.FindSecret(id)
if err != nil {
return fmt.Errorf("error retrieving secret %q: %v", id, err)
}
if secret == nil {
continue
}
err = describeSecret(id, secret, &b)
if err != nil {
return err
}
b.WriteString("\n")
_, err = w.Write(b.Bytes())
if err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
b.Reset()
}
}
return w.Flush()
}
示例12: InstancesInfo
func (client *FSouza_InstancesClient) InstancesInfo(logger log.Log) {
instances := client.instances
if instances.MachineName() == INSTANCES_NULL_MACHINENAME {
} else if len(instances.InstancesOrder()) == 0 {
logger.Message("|-= no containers")
} else {
logger.Message("|-> instances (containers) MachineName:" + instances.MachineName())
w := new(tabwriter.Writer)
w.Init(logger, 8, 12, 2, ' ', 0)
row := []string{
"|=",
"Name",
"Container",
"Default",
"Created",
"Running",
"Status",
"ID",
"Created",
"Names",
}
w.Write([]byte(strings.Join(row, "\t") + "\n"))
for _, name := range instances.InstancesOrder() {
instance, _ := instances.Instance(name)
machineName := instance.MachineName()
instanceClient := instance.Client()
row := []string{
"|-",
name,
machineName,
}
if instance.IsDefault() {
row = append(row, "yes")
} else {
row = append(row, "no")
}
if instanceClient.HasContainer() {
row = append(row, "yes")
} else {
row = append(row, "no")
}
if instanceClient.IsRunning() {
row = append(row, "yes")
} else {
row = append(row, "no")
}
containers, _ := client.backend.MatchContainers(machineName, false)
for _, container := range containers {
row = append(row,
container.Status,
container.ID[:12],
strconv.FormatInt(int64(container.Created), 10),
strings.Join(container.Names, ", "),
)
break
}
w.Write([]byte(strings.Join(row, "\t") + "\n"))
}
w.Flush()
}
}
示例13: writeRow
func writeRow(w *tabwriter.Writer, fields []string) (err error) {
s := strings.Join(fields, "\t")
_, err = w.Write([]byte(s + "\n"))
return err
}
示例14: Run
func (c *DeleteClusterCmd) Run() error {
var stateStore fi.StateStore
var err error
var cloud fi.Cloud
clusterName := ""
region := ""
if c.External {
region = c.Region
if region == "" {
return fmt.Errorf("--region is required")
}
clusterName := rootCommand.clusterName
if clusterName == "" {
return fmt.Errorf("--name is required (when --external)")
}
tags := map[string]string{"KubernetesCluster": clusterName}
cloud, err = awsup.NewAWSCloud(c.Region, tags)
if err != nil {
return fmt.Errorf("error initializing AWS client: %v", err)
}
} else {
stateStore, err = rootCommand.StateStore()
if err != nil {
return err
}
cluster, _, err := api.ReadConfig(stateStore)
if err != nil {
return err
}
if rootCommand.clusterName != cluster.Name {
return fmt.Errorf("sanity check failed: cluster name mismatch")
}
clusterName = cluster.Name
cloud, err = cloudup.BuildCloud(cluster)
if err != nil {
return err
}
}
d := &kutil.DeleteCluster{}
d.ClusterName = clusterName
d.Region = region
d.Cloud = cloud
resources, err := d.ListResources()
if err != nil {
return err
}
if len(resources) == 0 {
fmt.Printf("Nothing to delete\n")
} else {
columns := []string{"TYPE", "ID", "NAME"}
fields := []string{"Type", "ID", "Name"}
var b bytes.Buffer
w := new(tabwriter.Writer)
// Format in tab-separated columns with a tab stop of 8.
w.Init(os.Stdout, 0, 8, 0, '\t', tabwriter.StripEscape)
writeHeader := true
if writeHeader {
for i, c := range columns {
if i != 0 {
b.WriteByte('\t')
}
b.WriteByte(tabwriter.Escape)
b.WriteString(c)
b.WriteByte(tabwriter.Escape)
}
b.WriteByte('\n')
_, err := w.Write(b.Bytes())
if err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
b.Reset()
}
for _, t := range resources {
for i := range columns {
if i != 0 {
b.WriteByte('\t')
}
v := reflect.ValueOf(t)
if v.Kind() == reflect.Ptr {
v = v.Elem()
}
fv := v.FieldByName(fields[i])
s := fi.ValueAsString(fv)
b.WriteByte(tabwriter.Escape)
//.........这里部分代码省略.........