在命令行上使用Go,如何隐藏用户终端上的命令行输入?

I'm writing a simple command line utility that requests a password from the user. I settled on using bufio for reading user input and can't figure out how to hide the password on the user's terminal. Is this functionality in Go's standard library, or do I need to use OS-level functionality to accomplish this? (This is probably only going to run on Linux, but would prefer something that works on Windows also.)

What you want is turning off echoing. This is usually achieved by configuring the terminal driver, termios. Your best bet is to read Linux' documentation of that driver (termios(3)). As far as I am concerned, you need to turn off ECHO before reading a password. After reading the password, turn on ECHO again. Do not use bufio as you do not want to have buffering interfere with low-level terminal stuff. You can access the requires system calls from the syscall package.

termios is available on every UNIX-like platform. This includes Linux, BSD, OS X, and Solaris but not Microsoft Windows.

You can use termbox that uses keyboard input without output. So far i can tell, this works on Windows, but i am unsure if this works on Linux (i guess it does). Once installed, there is a _demos folder, inside of this folder there is an example called keyboard.go. Once started, it will show a keyboard and it highlights the keys that are pressed. However, it does work on my pc, but when i press space bar/enter/function keys or CTRL-(any)key, the program hangs. Maybe it's a bug in the code or inside of Termbox. I have not figured out yet. Also, you need to use CGO to use termbox to run.

Screenshot:

enter image description here