Golang fmt.Scan() function examples
package fmt
Scan scans text read from standard input, storing successive space-separated values into successive arguments. Newlines count as space. It returns the number of items successfully scanned. If that is less than the number of arguments, err will report why.
Golang fmt.Scan() function usage examples
Example 1 :
fmt.Printf("Enter 2 numbers> ")
fmt.Scan(&x)
fmt.Scan(&y)
fmt.Printf("Sending %d and %d\n", x, y)
Example 2 :
c := make(chan string)
go func() {
var o string
fmt.Scan(&o)
c <- o
}()
Example 3:
...
var (
readValue string
readSize int
)
readSize, err = fmt.Scan(&readValue)
if err != nil {
return
} else if readSize < 1 {
err = errors.New("Can't read input")
return
}
...
Reference :
Advertisement
Something interesting
Tutorials
+6.5k Golang : Map within a map example
+5.2k Golang : PGX CopyFrom to insert rows into Postgres database
+5.4k Python : Delay with time.sleep() function example
+9.3k Golang : How to get garbage collection data?
+17k Golang : Covert map/slice/array to JSON or XML format
+12.5k Golang : "https://" not allowed in import path
+11.4k Golang : Delay or limit HTTP requests example
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+8.8k Golang : Get final balance from bit coin address example
+6.2k Golang & Javascript : How to save cropped image to file on server
+29.5k Golang : Saving(serializing) and reading file with GOB
+7.5k Golang : Gorrila set route name and get the current route name