mirror of
https://github.com/mudabbir-ahmad/LearningGo.git
synced 2026-10-08 01:50:20 +00:00
Terminal reading
This commit is contained in:
1 parent
16d9c8b171
commit
b55e4c503f
2 files changed
+48
No files matched your search
@@ -0,0 +1,39 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func check(e error) {
|
||||||
|
if e != nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
|
// 1. Ask for Username
|
||||||
|
fmt.Print("Username: ")
|
||||||
|
usernameInput, err := reader.ReadString('\n')
|
||||||
|
|
||||||
|
check(err)
|
||||||
|
username := strings.TrimSpace(usernameInput)
|
||||||
|
|
||||||
|
// 2. Ask for Password (with asterisk masking)
|
||||||
|
fmt.Print("Password: ")
|
||||||
|
passwordIn, _ := reader.ReadString('\n')
|
||||||
|
password := string(passwordIn)
|
||||||
|
|
||||||
|
// 3. Output results
|
||||||
|
fmt.Println("\n--- Result ---")
|
||||||
|
fmt.Println("Username:", username)
|
||||||
|
fmt.Println("Password:", password)
|
||||||
|
|
||||||
|
fmt.Print("The delim should cause you to end the line whenever you press back slash, then hit enter: \n")
|
||||||
|
test, _ := reader.ReadString('\\')
|
||||||
|
fmt.Println("You entered:", test)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user