bind

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InKey  = "$_gomer_bind_in"
	OutKey = "$_gomer_bind_out"
)

Variables

View Source
var (
	PascalCaseFn casingFn = func(fieldName string) string { return fieldName } // Exported fields are already PascalCase
	CamelCaseFn  casingFn = func(fieldName string) string {

		firstChar := fieldName[0]
		if 'A' <= firstChar && firstChar <= 'Z' {
			firstChar += 'a' - 'A'
		}
		return string(firstChar) + fieldName[1:]
	}
)

Functions

func All

func All(_ string, _ any, _ reflect.Value) bool

func CamelCaseFields added in v0.2.0

func CamelCaseFields(c *Configuration)

func ExtendsWith

func ExtendsWith(extension ExtensionProvider) func(*Configuration)

func IncludeEmpty

func IncludeEmpty(c *Configuration)

func IsField

func IsField(key string, _ any, sv reflect.Value) bool

func IsNotField

func IsNotField(key string, _ any, sv reflect.Value) bool

func NewInTool

func NewInTool(bindConfig Configuration, dp structs.DirectiveProvider) *structs.Tool

NewInTool

<name> -> Default input value matching <name>. If name == "" then name = b.DataCase(StructField.Name) =<static> -> Application-defined static value $<function> -> Application-defined dynamic value ?<directive> -> Applied iff field.IsZero(). Supports chaining (e.g. "query.aName?header.A-Source?=aDefault") <directive>&<right> -> Applies the left directive followed by the right (e.g. "input&$transform) <directive>!<right> -> Applies the left directive and, if it succeeds, the right - -> Explicitly not bound from any input

func NewOutTool

func NewOutTool(bindConfig Configuration, dp structs.DirectiveProvider) *structs.Tool

NewOutTool

+ -> Use field name as value's key. Required if EmptyDirectiveHandling == skipField <name> -> Use 'name' as value's key (if PayloadBindingPrefix != "", form is similar to header) =<static> -> Static output value $<function> -> Function-derived output value ?<directive> -> Applied iff field.IsZero(). Supports chaining (e.g. "?$foo?=last") <directive>&<right> -> Will apply the left directive followed by the right (e.g. "=OutValue&header.X-My-Header) <directive>!<right> -> Applies the left directive and, if it succeeds, the right - -> Explicitly not included in the output

Except for '-', each of the above can be combined with an ",omitempty" or ",includempty" qualifier that acts like '-' or '+' respectively if the field's value is its zero Value.

func OmitEmpty

func OmitEmpty(c *Configuration)

func PascalCaseFields added in v0.2.0

func PascalCaseFields(c *Configuration)

func RegisterStashFieldFunction

func RegisterStashFieldFunction(name, sourceKey string, include InclusionPredicate)

func RegisterUnstashFieldFunction

func RegisterUnstashFieldFunction(name, destinationKey string, include InclusionPredicate, createIntermediates bool)

func UseStashed

func UseStashed(stashed, _ any) any

Types

type Binder added in v0.4.0

type Binder struct {
	InTool  *structs.Tool
	OutTool *structs.Tool
}

Binder holds a configured pair of in/out tools for binding data to and from structs. Create one via NewBinder and pass it explicitly to the components that need it.

func NewBinder added in v0.4.0

func NewBinder(options ...func(*Configuration)) *Binder

NewBinder creates a Binder with the provided configuration options.

binder := bind.NewBinder(bind.CamelCaseFields, bind.OmitEmpty)

func (*Binder) In added in v0.4.0

func (b *Binder) In(data map[string]any, v any, optional ...structs.ToolContext) gomerr.Gomerr

In binds data into v using this Binder's InTool.

func (*Binder) Out added in v0.4.0

func (b *Binder) Out(v any, optional ...structs.ToolContext) (map[string]any, gomerr.Gomerr)

Out binds v's fields into a map using this Binder's OutTool.

type Configuration

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

func CopyConfigurationWithOptions

func CopyConfigurationWithOptions(b Configuration, options ...func(*Configuration)) Configuration

func NewConfiguration

func NewConfiguration(options ...func(*Configuration)) Configuration

type ExtensionProvider

type ExtensionProvider interface {
	structs.ApplierProvider
	Type() string
}

type InclusionPredicate

type InclusionPredicate func(key string, value any, sv reflect.Value) bool

func IfAll

func IfAll(predicates ...InclusionPredicate) InclusionPredicate

func IfAny

func IfAny(predicates ...InclusionPredicate) InclusionPredicate

func NameMatches

func NameMatches(names ...string) InclusionPredicate

type UnstashConflictResolver

type UnstashConflictResolver func(stashed, destination any) any

func MergeStashed

func MergeStashed(include InclusionPredicate) UnstashConflictResolver

Jump to

Keyboard shortcuts

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