github.com/gogf/gf/v2@v2.7.4/os/gcmd/gcmd_scan.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 // 7 8 package gcmd 9 10 import ( 11 "bufio" 12 "fmt" 13 "os" 14 15 "github.com/gogf/gf/v2/text/gstr" 16 ) 17 18 // Scan prints `info` to stdout, reads and returns user input, which stops by '\n'. 19 func Scan(info ...interface{}) string { 20 fmt.Print(info...) 21 return readline() 22 } 23 24 // Scanf prints `info` to stdout with `format`, reads and returns user input, which stops by '\n'. 25 func Scanf(format string, info ...interface{}) string { 26 fmt.Printf(format, info...) 27 return readline() 28 } 29 30 func readline() string { 31 var s string 32 reader := bufio.NewReader(os.Stdin) 33 s, _ = reader.ReadString('\n') 34 s = gstr.Trim(s) 35 return s 36 }