Golang fmt.Fscan() function examples
package flag
Fscan scans text read from r(1st parameter), 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.Fscan() function usage examples
Example 1:
func promptForString(field string, r io.Reader) string {
fmt.Printf("Please enter %s: ", field)
var result string
fmt.Fscan(r, &result)
return result
}
Example 2:
func KeysFromFile(name string) (string, string, error) {
file, err := os.Open(name)
if err != nil {
return "", "", err
}
defer file.Close()
var secret, access string
_, err = fmt.Fscan(file, &secret, &access) // <-- here
return secret, access, err
}
Reference :
Advertisement
Something interesting
Tutorials
+19.1k Golang : Display list of time zones with GMT
+29.3k Golang : Save map/struct to JSON or XML file
+26.8k Golang : Find files by extension
+12.5k Golang : Forwarding a local port to a remote server example
+6.4k Golang : How to search a list of records or data structures
+12k Golang : Clean formatting/indenting or pretty print JSON result
+6.8k Golang : Muxing with Martini example
+5.4k Python : Delay with time.sleep() function example
+10.8k Golang : Command line file upload program to server example
+14.3k Golang : How to shuffle elements in array or slice?
+17.2k Golang : Find file size(disk usage) with filepath.Walk