Help us shape the future of Go! Take the 2026 Go Developer Survey

sleepycat

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

README

sleepycat

sleepycat is a Go package for reading user input from the terminal.

The package provides typed input functions and a consistent option-based API for prompts, validation, and retry behavior.

Status: Work in progress. The API is not yet stable.

Installation

go get github.com/Rajdeep-Nemo/sleepycat

Example

package main

import (
	"fmt"
	"os"

	"github.com/Rajdeep-Nemo/sleepycat"
)

func main() {
	age, err := sleepycat.Int(
		sleepycat.Prompt("Enter age: "),
		sleepycat.MaxAttempt(3),
	)
	if err != nil {
		fmt.Println(err)
		os.Exit(0)
	}

	fmt.Println(age)
}

Available

Input
  • Int()
  • Float32()
  • Float64()
  • Bool()
  • String()
  • Byte()
  • Rune()
Options
  • Prompt()
  • MaxAttempt()

Project Structure

sleepycat/
├── .github/
│   └── workflows/
│       └── ci.yml              # Continuous integration
│
├── examples/                   # Example programs
│   ├── int/
│   │   └── main.go             
│   └── ...                     # More Examples
│
├── internal/
│   └── input.go                # Terminal input helpers
│
├── config.go                   # Config and functional options
├── parser.go                   # Shared parsing/retry logic
├── int.go                      # Integer input
├── float32.go                  # 32 bit float input
├── float64.go                  # 64 bit float input
├── ...                         # Other inputs
│
├── helpers_test.go             # Shared helper functions
├── int_test.go
├── float32_test.go
├── float64_test.go
├── ...                         # Other test cases
│
├── .gitignore
├── go.mod
├── go.sum
├── LICENSE
└── README.md

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(opts ...option) (bool, error)

Bool reads from the input source and returns a boolean value (true/false)

func Byte

func Byte(opts ...option) (byte, error)

Read from the input source and returns a `byte` value

func Float32

func Float32(opts ...option) (float32, error)

Float32 reads an floating point number from the input source and returns as `float32`

func Float64

func Float64(opts ...option) (float64, error)

Float64 reads an floating point number from the input source and returns as `float64`

func Int

func Int(opts ...option) (int, error)

Int reads an integer from the input source.

func MaxAttempt

func MaxAttempt(count int) option

MaxAttempts limits the number of invalid input attempts. A value of 0 retries indefinitely.

func Prompt

func Prompt(inputPrompt string) option

Prompt sets the text printed before waiting for input.

func Rune added in v0.8.0

func Rune(opts ...option) (rune, error)

Read from the input source and returns a unicode code point

func String

func String(opts ...option) (string, error)

String reads from the input source and returns a string literal MaxAttempt does not work as there is no invalid string

Types

This section is empty.

Directories

Path Synopsis
examples
boolean command
byte command
float32 command
float64 command
int command
rune command
string command

Jump to

Keyboard shortcuts

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