O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter05/recipe01.
  2. Navigate to the directory.
  3. Create the fmt.go file with the following content:
        package main        import (          "fmt"        )        func main() {          var name string          fmt.Println("What is your name?")          fmt.Scanf("%s\n", &name)          var age int          fmt.Println("What is your age?")          fmt.Scanf("%d\n", &age)          fmt.Printf("Hello %s, your age is %d\n", name, age)       }
  1. Execute the code with go run fmt.go.
  2. Enter the input John and press Enter.
  3. Enter the input 40 and press Enter.
  1. You will see the following output:
  1. Create the file scanner.go with the following content:
        package main        import (          "bufio"          "fmt" "os" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required