Documentation
¶
Overview ¶
Package wbctljson contains wbctl-specific JSON marshaling and unmarshaling helpers used to bridge user-facing CLI payloads and canonical API structs.
The package provides:
- MakeMarshaler, a reflection-based marshaler that can emit full view JSON or edit-only payloads.
- MakeUnmarshaler, a normalizing unmarshaler that rewrites wbctl field names before typed decoding.
- Shared tag parsing and normalization helpers that apply wbctl metadata consistently for both encode and decode paths.
Tag handling:
- Standard `json` tags remain the canonical schema contract, including field naming, `omitempty`, and `json:"-"` exclusion.
- `wbctl:"editable"` gates fields included in edit payload output, letting view output stay complete while edit output stays intentionally narrow.
- `wbctl:"seedfield:<FieldName>"` allows an editable field to use a fallback value when the primary field is zero-valued, supporting stable edit payloads for mirrored state fields.
- `wbctl:"-"` excludes a field from wbctl-specific processing even if other wbctl metadata is present.
Recursion:
- Marshal recursion follows three root/container kinds (struct, map, slice), and applies wbctl filtering recursively for nested struct values.
- Map/slice recursion intentionally recurses only into struct entries and leaves scalar/non-struct values to encoding/json, preserving native JSON behavior where wbctl metadata does not apply.
- Pointer/interface wrappers are unwrapped before recursion decisions so traversal is based on concrete payload shape instead of wrapper kinds.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var EditOptions = MarshalerOptions{ EditOnly: true, Pretty: true, Indent: " ", }
EditOptions is the set of options used when marshaling a resource for the user to edit. This is either via the edit command or via the --dry-run option passed to update or create.
var ViewOptions = MarshalerOptions{ EditOnly: false, Pretty: true, Indent: " ", }
ViewOptions is the set of options used when marshaling a resource for the customer to view.
Functions ¶
func MakeMarshaler ¶
func MakeMarshaler[T any](opts MarshalerOptions) func(T) ([]byte, error)
MakeMarshaler returns s function that marshals a struct (or struct pointer) to JSON, if editOnly is true then only fields tagged with `wbctl:"editable"` will be included. It also accepts map[string]any and applies the same editable-field filtering to struct values in the map at any nesting level as long as it is map[string]any all the way to the struct (see "nested valid map" test).
Types ¶
type MarshalerOptions ¶
MarshalerOptions are the options that control the wbctljson marshaling functions.