Documentation ¶
Overview ¶
Package value handles mapping values to the settings type. The package can handle input from a number of source and allows values to be mapped to a provided pointer so that the calling program can deal with concrete types.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidType is returned if an attempt is made to Coerce data to an // unsupported type. ErrInvalidType = errors.New("value.Data: invalid type") // ErrAssignmentFailure is returned if the Data type can't be assigned to // the given type. ErrAssignmentFailure = errors.New("value.Data: assignment failure") // ErrInvalidPointerType is returned if the Pointer in the Data type isn't // supported. ErrInvalidPointerType = errors.New("value.Data: invalid pointer type") )
Functions ¶
Types ¶
type Data ¶
type Data struct { Set bool Pointer interface{} }
Data holds an untyped (interface{}) value which can be assigned to a bool, int, int64, uint, uint64, float64, string, or time.Duration.
func Coerce ¶
Coerce the given string into a Data type holding a value of typeOf. If the data cannot be coerced the the underlying parse error will be returned. An invalid typeOf will result in ErrInvalidType.
Example ¶
package main import ( "fmt" "bitbucket.org/idomdavis/goconfigure/value" ) func main() { var typeOf string if v, err := value.Coerce("text", &typeOf); err != nil { fmt.Println(err) } else { fmt.Println(v) } }
Output: {true text}
func (Data) AssignTo ¶
AssignTo sets the given pointer to point to the value held by this Data type. ErrInvalidPointerType is returned if the given pointer is not a valid type, or is not a reflect.Ptr. ErrAssignmentFailure is returned if there is an error assigning the Data type to the pointer.
Example ¶
package main import ( "fmt" "bitbucket.org/idomdavis/goconfigure/value" ) func main() { var v string d := value.New("example") if err := d.AssignTo(&v); err != nil { fmt.Println(err) } fmt.Println(v) }
Output: example