yaorm: github.com/geoffreybauduin/yaorm/_vendor/github.com/lann/builder Index | Files

package builder

import "github.com/geoffreybauduin/yaorm/_vendor/github.com/lann/builder"

Package builder provides a method for writing fluent immutable builders.

Index

Package Files

builder.go reflect.go registry.go

Variables

var (
    EmptyBuilder = Builder{ps.NewMap()}
)

func Append Uses

func Append(builder interface{}, name string, vs ...interface{}) interface{}

Append returns a copy of the given builder with new value(s) appended to the named list. If the value was previously unset or set with Set (even to a e.g. slice values), the new value(s) will be appended to an empty list.

func Delete Uses

func Delete(builder interface{}, name string) interface{}

Delete returns a copy of the given builder with the given named value unset.

func Extend Uses

func Extend(builder interface{}, name string, vs interface{}) interface{}

Extend behaves like Append, except it takes a single slice or array value which will be concatenated to the named list.

Unlike a variadic call to Append - which requires a []interface{} value - Extend accepts slices or arrays of any type.

Extend will panic if the given value is not a slice, array, or nil.

func Get Uses

func Get(builder interface{}, name string) (interface{}, bool)

Get retrieves a single named value from the given builder. If the value has not been set, it returns (nil, false). Otherwise, it will return (value, true).

If the named value was last set with Append or Extend, the returned value will be a slice. If the given Builder has been registered with Register or RegisterType and the given name is an exported field of the registered struct, the returned slice will have the same type as that field. Otherwise the slice will have type []interface{}. It will panic if the given name is a registered struct's exported field and the value set on the Builder is not assignable to the field.

func GetMap Uses

func GetMap(builder interface{}) map[string]interface{}

GetMap returns a map[string]interface{} of the values set in the given builder.

See notes on Get regarding returned slices.

func GetStruct Uses

func GetStruct(builder interface{}) interface{}

GetStruct builds a new struct from the given registered builder. It will return nil if the given builder's type has not been registered with Register or RegisterValue.

All values set on the builder with names that start with an uppercase letter (i.e. which would be exported if they were identifiers) are assigned to the corresponding exported fields of the struct.

GetStruct will panic if any of these "exported" values are not assignable to their corresponding struct fields.

func GetStructLike Uses

func GetStructLike(builder interface{}, strct interface{}) interface{}

GetStructLike builds a new struct from the given builder with the same type as the given struct.

All values set on the builder with names that start with an uppercase letter (i.e. which would be exported if they were identifiers) are assigned to the corresponding exported fields of the struct.

ScanStruct will panic if any of these "exported" values are not assignable to their corresponding struct fields.

func Register Uses

func Register(builderProto interface{}, structProto interface{}) interface{}

Register wraps RegisterType, taking instances instead of Types.

Returns an empty instance of the registered builder type which can be used as the initial value for builder expressions. See example.

func RegisterType Uses

func RegisterType(builderType reflect.Type, structType reflect.Type) *reflect.Value

RegisterType maps the given builderType to a structType. This mapping affects the type of slices returned by Get and is required for GetStruct to work.

Returns a Value containing an empty instance of the registered builderType.

RegisterType will panic if builderType's underlying type is not Builder or if structType's Kind is not Struct.

func Set Uses

func Set(builder interface{}, name string, v interface{}) interface{}

Set returns a copy of the given builder with a new value set for the given name.

Set (and all other functions taking a builder in this package) will panic if the given builder's underlying type is not Builder.

type Builder Uses

type Builder struct {
    // contains filtered or unexported fields
}

Builder stores a set of named values.

New types can be declared with underlying type Builder and used with the functions in this package. See example.

Instances of Builder should be treated as immutable. It is up to the implementor to ensure mutable values set on a Builder are not mutated while the Builder is in use.

Package builder imports 3 packages (graph) and is imported by 1 packages. Updated 2017-09-01. Refresh now. Tools for package owners.