parse

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package parse implements a reflection-based mechanism of converting a string (e.g. from an environment variable or from a struct field) into a Go type for the struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinaryUnmarshalerFrom

func BinaryUnmarshalerFrom(field *structs.Field) (b encoding.BinaryUnmarshaler)

Attempts to get an encoding.BinaryUnmarshaler variable from the specified field.

func BinaryUnmarshalerFromValue

func BinaryUnmarshalerFromValue(field reflect.Value) (b encoding.BinaryUnmarshaler)

Attempts to get an encoding.BinaryUnmarshaler variable from the specified value.

func IsDecodable

func IsDecodable(field *structs.Field) bool

Returns true if the field implements one of the decodable interfaces.

func Parse

func Parse(value string, field reflect.Value) error

func ParseField

func ParseField(value string, field *structs.Field) error

ParseField parses the given type from the field and sets it.

func TextUnmarshalerFrom

func TextUnmarshalerFrom(field *structs.Field) (t encoding.TextUnmarshaler)

Attempts to get an encoding.TextUnmarshaler variable from the specified field.

func TextUnmarshalerFromValue

func TextUnmarshalerFromValue(field reflect.Value) (t encoding.TextUnmarshaler)

Attempts to get an encoding.TextUnmarshaler variable from the specified value.

Types

type Decoder

type Decoder interface {
	Decode(value string) error
}

Decoder has the same semantics as Setter, but takes higher precedence.

func DecoderFrom

func DecoderFrom(field *structs.Field) (d Decoder)

Attempts to get a Decoder variable from the specified field.

func DecoderFromValue

func DecoderFromValue(field reflect.Value) (d Decoder)

Attempts to get a Decoder variable from the specified value.

type Setter

type Setter interface {
	Set(value string) error
}

Setter is implemented by types can self-deserialize values. Any type that implements flag.Value also implements Setter.

func SetterFrom

func SetterFrom(field *structs.Field) (s Setter)

Attempts to get a Setter variable from the specified field.

func SetterFromValue

func SetterFromValue(field reflect.Value) (s Setter)

Attempts to get a Setter variable from the specified value.

Jump to

Keyboard shortcuts

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