value

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package value handles mapping values pass into the application via various means to the settings type.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chase

func Chase(in interface{}) reflect.Type

Chase down the actual type of an interface. If it's a pointer get the type being pointed to, if that's an interface get the underlying type for that.

Types

type Data

type Data struct {
	Set bool
	// contains filtered or unexported fields
}

Data holds an untyped (interface{}) value which can be assigned to a bool, int, int64, uint, uint64, float64, string, or time.Duration.

func Coerce

func Coerce(data string, typeOf interface{}) (Data, error)

Coerce the given string into a Data type holding a value of typeOf.

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 New

func New(data interface{}) Data

New creates a new Data type with the given value.

func (Data) AssignTo

func (d Data) AssignTo(pointer interface{}) (err error)

AssignTo sets the given pointer to point to the value held by this Data type.

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

func (Data) Pointer

func (d Data) Pointer() interface{}

Pointer returns the underlying value wrapped by this data type.

Jump to

Keyboard shortcuts

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