Terminal reading

This commit is contained in:
bobbert committed 2026-07-17 01:28:20 +01:00
1 parent 16d9c8b171
commit b55e4c503f
2 files changed
+48

No files matched your search

+39
View File
@@ -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)
}
+9
View File
@@ -1 +1,10 @@
module LearningGo
go 1.26.5
require (
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef // indirect
golang.org/x/crypto v0.54.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/term v0.45.0 // indirect
)