gcmd
组件支持从终端读取用户输入数据,常用于终端交互场景。
相关方法:
func Scan(info ...interface{}) string
func Scanf(format string, info ...interface{}) string
这两个方法都是向终端展示给定的信息,自动读取终端用户输入的信息返回,通过回车符号返回。
package main
import (
"fmt"
"github.com/gogf/gf/v2/os/gcmd"
)
func main() {
name := gcmd.Scan("What's your name?\n")
fmt.Println("Your name is:", name)
}
执行后,交互示例:
> What's your name?
john
> Your name is: john
package main
import (
"fmt"
"github.com/gogf/gf/v2/os/gcmd"
)
func main() {
name := gcmd.Scan("> What's your name?\n")
age := gcmd.Scanf("> Hello %s, how old are you?\n", name)
fmt.Printf("> %s's age is: %s", name, age)
}
执行后,交互示例:
> What's your name?
john
> Hello john, how old are you?
18
> john's age is: 18
备案信息: 粤ICP备15087711号-2
Copyright © 2008-2024 啊嘎哇在线工具箱 All Rights.
本站所有资料来源于网络,版权归原作者所有,仅作学习交流使用,如不慎侵犯了您的权利,请联系我们。