scan

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 5 Imported by: 0

README

Scan

Functions for reading user input from stdin.

License

Sponsorship

BoostySupport

Bitcoin

1CCnwAvJYEoDVGM7vsBg2Q99cF9EHtBVaY

Tether

0x54f0ccc6b2987de454f69f2814fc9202bcfb74fe

Table of Contents

Features

  • Simple single-line input reading
  • Returns io.EOF when input is closed (Ctrl+D)
  • Type conversion with error handling

Installation

go get github.com/andmitr/pkg/scan

Usage

func String
func String() (string, error)

String reads a single line from stdin and returns it as a string.

Example
fmt.Print("Enter your name: ")
name, err := scan.String()
if errors.Is(err, io.EOF) {
    fmt.Println("Input closed")
    return
}
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Hello, %s!\n", name)
func Int
func Int() (int, error)

Int reads a single line from stdin and returns it as an int.

Example
fmt.Print("Enter your age: ")
age, err := scan.Int()
if err != nil {
    log.Fatal(err)
}
fmt.Printf("You are %d years old\n", age)
func Float
func Float() (float64, error)

Float reads a single line from stdin and returns it as a float64.

Example
fmt.Print("Enter price: ")
price, err := scan.Float()
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Price: %.2f\n", price)

License

MIT Licensed. See LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Float

func Float() (float64, error)

Float reads a single line from stdin and returns it as a float64.

Returns io.EOF when input is closed.

func Int

func Int() (int, error)

Int reads a single line from stdin and returns it as an int.

Returns io.EOF when input is closed.

func String

func String() (string, error)

String reads a single line from stdin and returns it as a string.

Returns io.EOF when input is closed.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL