parse

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package parse is used to convert strings when the target type is unknown at compile-time.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignValue

func AssignValue(field reflect.Value, text string) error

AssignValue parses the string ans assigns the value to the field. The parse will be selected based on the field's type. The field must either be a non-nil pointer, or an addressable and settable value.

Types

type ConversionError

type ConversionError struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"
	"reflect"

	"git.sr.ht/~rj/flags/internal/parse"
)

func main() {
	var i int

	err := parse.AssignValue(reflect.ValueOf(&i), "123.4")
	if err != nil {
		fmt.Printf("error: %s\n", err)
	}

}
Output:

error: could not convert '123.4': strconv.ParseInt: parsing "123.4": invalid syntax

func (*ConversionError) Error

func (e *ConversionError) Error() string

func (*ConversionError) Unwrap

func (e *ConversionError) Unwrap() error

type Value

type Value interface {
	String() string
	Set(string) error
}

Value is the interface to the dynamic value stored in a flag.

Jump to

Keyboard shortcuts

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