wbctljson

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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).

func MakeUnmarshaler

func MakeUnmarshaler[T any]() func(io.Reader, *T) error

MakeUnmarshaler returns a function that accepts wbctl JSON and normalizes field names before decoding into the typed API struct.

Types

type MarshalerOptions

type MarshalerOptions struct {
	EditOnly bool
	Pretty   bool
	Indent   string
}

MarshalerOptions are the options that control the wbctljson marshaling functions.

Jump to

Keyboard shortcuts

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