input Module
The input module provides buffered console input utilities (built on Go's bufio over os.Stdin). All functions follow Harneet's convention of returning (result, error) tuples.
When an input parse fails (e.g., invalid integer), the function returns (None, error) with a helpful message.
Functions
ReadLine()
Reads a single line from standard input and returns it without the trailing newline.
- Parameters: none
- Returns:
(string, error)
Example:
| Read Line | |
|---|---|
ReadWord()
Reads the first whitespace-delimited token from the next line of input.
- Parameters: none
- Returns:
(string, error)
Example:
| Read Word | |
|---|---|
ReadWords()
Reads a line from standard input and splits it into whitespace-delimited tokens.
- Parameters: none
- Returns:
(array, error)(array of strings)
Example:
| Read Words | |
|---|---|
ReadInt()
Reads a line and parses it as a base-10 integer.
- Parameters: none
- Returns:
(int, error)
Example:
| Read Integer | |
|---|---|
ReadFloat()
Reads a line and parses it as a float64.
- Parameters: none
- Returns:
(float64, error)
Example:
| Read Float | |
|---|---|
ReadBool()
Reads a line and parses it as a boolean. Accepted values (case-insensitive): true, t, 1, yes, y, false, f, 0, no, n.
- Parameters: none
- Returns:
(bool, error)
Example:
| Read Boolean | |
|---|---|
Prompt(message string)
Prints a prompt message to stdout and reads a single line from standard input.
- Parameters:
message(string): prompt to display before reading input- Returns:
(string, error)
Example: