hooks

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package hooks provides mapstructure decode hooks for use with DcValue[T] fields. When decoding YAML or map[string]any data into structs containing DcValue[T] fields, use MapstructureHookFunc() so that mapstructure automatically constructs properly-typed DcValue instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapstructureHookFunc

func MapstructureHookFunc() mapstructure.DecodeHookFunc

MapstructureHookFunc returns a mapstructure.DecodeHookFunc that detects target fields of type *poya.DcValue[T] and initializes them from the decoded source data.

For scalar T types (string, int, bool, etc.), the source value is set directly. For struct T types, the source value (typically map[string]any from YAML decoding) is JSON-marshaled and then set via InternalSetJSON.

Usage:

decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
    DecodeHook: hooks.MapstructureHookFunc(),
    Result:     &cfg,
})
if err != nil { ... }
err = decoder.Decode(viper.AllSettings())

func MapstructureHookFuncValue

func MapstructureHookFuncValue() mapstructure.DecodeHookFuncValue

MapstructureHookFuncValue returns a mapstructure.DecodeHookFuncValue for use with ComposeDecodeHookFunc or when the value hook type is needed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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