Go Standard Library Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Open the console and create the folder chapter02/recipe05.
  2. Navigate to the directory.
  3. Create the tabwriter.go file with the following content:
        package main

import (
"fmt"
"os"
"text/tabwriter"
)

func main() {

w := tabwriter.NewWriter(os.Stdout, 15, 0, 1, ' ',
tabwriter.AlignRight)
fmt.Fprintln(w, "username\tfirstname\tlastname\t")
fmt.Fprintln(w, "sohlich\tRadomir\tSohlich\t")
fmt.Fprintln(w, "novak\tJohn\tSmith\t")
w.Flush()

}
  1. Run the code by executing go run tabwriter.go.
  2. See the output in the Terminal: