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
+4.9k Nginx and PageSpeed build from source CentOS example
+8.4k Golang : Generate Datamatrix barcode
+10.8k PHP : Convert(cast) bigInt to string
+6.6k Golang : Embedded or data bundling example
+11.7k Golang : Gorilla web tool kit secure cookie example
+9.4k Golang : Play .WAV file from command line
+7.3k Golang : Not able to grep log.Println() output
+5.3k Golang : Generate Interleaved 2 inch by 5 inch barcode
+18.9k Golang : Read input from console line
+12.4k Elastic Search : Return all records (higher than default 10)
+11.1k Golang : Simple image viewer with Go-GTK
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date