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
+12.8k Swift : Convert (cast) Int or int32 value to CGFloat
+7.1k Golang : Get environment variable
+20.8k Golang : Underscore or snake_case to camel case example
+21.1k Golang : Sort and reverse sort a slice of strings
+16.3k Golang :Trim white spaces from a string
+5.7k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+28.7k Golang : Detect (OS) Operating System
+7.5k Golang : Create zip/ePub file without compression(use Store algorithm)
+22.2k Golang : Securing password with salt
+24.5k Golang : How to validate URL the right way
+7.4k Golang : Hue, Saturation and Value(HSV) with OpenCV example