input

package
v0.0.0-...-5c98b36 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: MulanPSL-2.0 Imports: 5 Imported by: 0

README

input 命令行的用户输入

简化提示用户输入的操作,提供提示、默认值、检查函数。

当用户输入的类型不正确,或者检查函数返回 false 时,再次提示用户输入。只有用户输入正确的值才返回。

Example:

package main

import (
	"bytes"
	"fmt"

	"gitee.com/sillyman/simpleUtil/common/input"
	"gitee.com/sillyman/simpleUtil/network/macaddr"
)

func main() {
	target := input.MAC("请输入A公司的设备(oui:001e6e)的MAC地址", macaddr.MustParse("001e-6e00-0001"), func(v macaddr.MAC) bool {
		return bytes.Equal(v[:3], []byte{0x0, 0x1e, 0x6e})
	})

	fmt.Println(target.String())
}

运行:

go run .\main.go
请输入A公司的设备(oui:001e6e)的MAC地址(001e-6e00-0001): abc
请输入A公司的设备(oui:001e6e)的MAC地址(001e-6e00-0001): 0023-5555-5555
请输入A公司的设备(oui:001e6e)的MAC地址(001e-6e00-0001): 001e-6e01-a4ff
001e-6e01-a4ff

Documentation

Overview

Package input 命令行的用户输入

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Float64

func Float64(prompt string, defaultVal float64, checkFn func(v float64) bool) float64

func IP

func IP(prompt string, defaultValue net.IP, checkFn func(v net.IP) bool) net.IP

func Int

func Int(prompt string, defaultVal int64, checkFn func(v int64) bool) int64

func MAC

func MAC(prompt string, defaultValue macaddr.MAC, checkFn func(v macaddr.MAC) bool) macaddr.MAC

func String

func String(prompt string, defaultVal string, checkFn func(v string) bool) string

String 提示用户输入,然后返回用户输入的值。 参数:

prompt 用户输入前的提示
defaultVal 默认的值,如果用户直接回车则返回默认值
checkFn 检查函数,如果返回false,则继续提示用户输入

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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