getpasswd functionality in Go?

前端 未结 9 1669
春和景丽
春和景丽 2020-12-02 13:08

Situation:

I want to get a password entry from the stdin console - without echoing what the user types. Is there something com

9条回答
  •  庸人自扰
    2020-12-02 13:44

    You can get the behavior you want with the Read method from the os.File object (or the os.Stdin variable). The following sample program will read a line of text (terminated with by pressing the return key) but won't echo it until the fmt.Printf call.

    package main
    
    import "fmt"
    import "os"
    
    func main() {
      var input []byte = make( []byte, 100 );
      os.Stdin.Read( input );
      fmt.Printf( "%s", input );
    }
    

    If you want more advanced behavior, you're probably going to have to use the Go C-wrapper utilities and create some wrappers for low-level api calls.

提交回复
热议问题