input

package
v0.0.0-...-ba7cdbd Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2014 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Input

func Input(input string, out interface{}, tag *structs.Tag, required bool) error

Input is a shorthand for InputNamed("", ...).

func InputNamed

func InputNamed(name string, input string, out interface{}, tag *structs.Tag, required bool) error

InputNamed takes a (generally) user-provided input string and parses it into the out parameter, which must be settable (this usually means you'll have to pass a pointer to this function). See the documentation on Parse() for a list of the supported types. If name is provided, it will be included in any error returned by this function. Additional constraints might be specified with the tag parameter, the ones currently supported are:

  • required: Marks the field as required, will return an error if it's empty.
  • optional: Marks the field as optional, will accept empty values.
  • max_length: Sets the maximum length for the input.
  • min_length: Sets the minimum length for the input.
  • alphanumeric: Requires the input to be only letters and numbers

Finally, the required parameter indicates if the value should be considered required or optional in absence of the "required" and "optional" tag fields.

func Parse

func Parse(val string, arg interface{}) error

Parse tries to parse an string into the given argument. e.g.

var f float32
Parse("27.5", &f)
var width uint
Parse("57", &width)

Supported types are: string, bool, u?int(8|16|32|64)? and float(32|64). If the parsed value would overflow the given type, the maximum value (or minimum, if it's negative) for the type will be set. If arg implements the Parser interface, its Parse method will be used instead.

func RequiredInputError

func RequiredInputError(name string) error

RequiredInputError returns an error indicating that the parameter with the given name is required but it's missing. Note that this function is only exported to avoid user-visible string duplication and users should not use it.

Types

type Parser

type Parser interface {
	Parse(s string) error
}

Parser is the interface implemented by types that know how to parse themselves from a user provided string.

type Strings

type Strings []string

Strings implements the Parser interface, splitting the parsed string between commas. Strings containing commas might be quoted

func (Strings) Parse

func (s Strings) Parse(val string) error

Jump to

Keyboard shortcuts

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