Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-go

Go SDK library and RPC client for the Solana Blockchain

View on GitHub

26 documents · Updated Nov 16, 2026

docs / comparison-text-and-logging

Comparison, text, and logging utilities

These utilities support diagnosis and human inspection around the SDK's core Solana data flows. The diff package explains how two values differ, the text packages turn values and domain objects into readable output, and the logging integration exposes internal events through the SDK's structured logging system. They help engineers inspect state and failures without changing the functional APIs that build, encode, or send Solana data.

Utility role

The utilities form a support layer around functional SDK operations. Comparison produces structured change events, text produces display output, and logging records internal activity for an operator or developer.

The parent page, Supporting utilities, places these tools beside the other helpers that aid inspection and integration.

Comparison diagnostics

The diff package compares two Go values and reports only the changes. It is suited to state inspection, update diagnosis, and checks where a complete serialized value would hide the important difference.

Structured value differences

github.com/gagliardetto/solana-go/diff reports each difference as an event with a path, a kind, and the old or new value. A kind is one of added, changed, or removed, so a caller can handle a change without parsing display text. The path describes where the value sits inside a struct or slice.

The package sends events to a callback. It does not return a replacement value, apply a patch, or decide whether a difference is valid for a Solana instruction or transaction. Callers remain responsible for the business meaning of each event.

References: diff/diff.go• L27-52 diff/diff.go• L54-110 diff/diff.go• L195-210

Difference filtering

An event can match a field path or a path pattern for a slice position. This lets a diagnostic focus on one part of a nested value while keeping the full comparison independent of the caller's rules.

Slice changes use added and removed events rather than a semantic move operation. A caller that needs to treat a reorder as a move must apply that meaning outside the comparison utility.

The following flow shows the boundary between comparison and caller action:

flowchart LR
    A[Left value] --> C[Value comparison]
    B[Right value] --> C
    C --> E[Change events]
    E --> F[Path or kind filter]
    F --> G[Diagnostic or caller decision]

References: diff/diff.go• L75-104 diff/diff.go• L113-148 diff/diff.go• L226-266

Text presentation

The text package provides readable output for values that are hard to inspect in binary or default Go form. It supports nested values, domain-specific display types, indentation, and optional terminal color so command-line diagnostics can show structure without changing the underlying value.

Human-readable values

github.com/gagliardetto/solana-go/text accepts ordinary scalar, pointer, array, slice, map, and struct values. It can also use a type's TextEncode method through the TextEncodable contract when a type needs a specific display form.

The package includes display types for values such as hexadecimal bytes, booleans, fixed-width integers, and 128-bit numbers. These types affect presentation only. They do not replace the SDK's binary encoders, transaction builders, instruction builders, or RPC methods.

Struct text tags can request a linear layout, omit a type name, or skip a field. This gives a domain type control over diagnostic output while keeping the normal data model unchanged.

References: text/interface.go• L15-18 text/encoder.go• L33-72 text/encoder.go• L79-163 text/types.go• L25-40 text/types.go• L87-140 text/tag.go• L22-45

Terminal and tree output

Text helpers support two common inspection forms. The reflective encoder writes nested values to an io.Writer, while tree output lets a type describe a hierarchical view through the treeout model. Small string helpers add spacing, line breaks, highlighting, and color for command-line messages.

Color is optional presentation state. Set text.DisableColors when output must remain plain, such as logs, redirected command output, or comparisons of generated text. Color helpers return the input unchanged when this switch is enabled.

References: text/encoder.go• L38-52 text/encoder.go• L167-247 text/tree.go• L23-40 text/tools.go• L26-53 text/tools.go• L55-66 text/tools.go• L242-255

Structured logging

The SDK connects its packages to streamingfast/logging and uses zap loggers for structured diagnostic records. Logging is an observation channel for internal behavior. It is not part of transaction or instruction semantics.

Logger scope

The root SDK package registers a logger under the SDK module name. The diff package registers its own scope and checks a trace setting before writing path traversal and event details. This keeps verbose comparison traces opt-in while preserving a shared structured logging setup.

Other SDK areas can register their own scopes in the same way. A logger that is not configured remains a no-op logger, so callers can use the library without setting up logging first.

References: logging.go• L18-30 diff/logging.go• L17-30 diff/diff.go• L218-274

Functional API boundary

These packages explain or display SDK data, but they do not perform the SDK's main functional work. The comparison utility observes two values, the text utility renders a value, and logging records an event; none of them sends an RPC request, signs a transaction, encodes an instruction for the chain, or changes caller state.

Use the functional APIs when the program must create valid Solana data or communicate with the network. Add these utilities when the program must answer why two states differ, make a value readable to a person, or preserve structured evidence about an internal path.

Change checklist

When these files or sections are changed, remember to consider these:

  • Preserve the diff.Event contract when changing comparison behavior. Consumers may depend on event kind, path text, and the old or new value being present for the selected kind.
  • Keep slice reporting aligned with path matching. Added and removed slice events use path forms that can include unknown source or destination indexes.
  • Keep TextEncodable output separate from binary and wire encodings. A display change must not silently change data sent to Solana.
  • Keep plain-output behavior aligned with text.DisableColors. Command output and log capture can depend on the absence of terminal escape codes.
  • Keep logging scopes stable when moving diagnostic calls. Operators may enable trace output by package scope.

Important failure modes

TriggerConsequenceGuard
Calling diff.Diff without an OnEvent optionThe comparison panics instead of reporting changesAlways provide an event callback for diagnostic comparisons
Treating slice add/remove events as a move operationA reorder can be given the wrong business meaningInterpret slice paths and event kinds in the caller
Comparing colored text or logging colored outputEscape codes can make text differ even when its visible content matchesSet text.DisableColors for plain or machine-captured output
Expecting text output to define wire dataA readable representation can be mistaken for a valid binary or RPC valueUse the SDK's functional encoders and RPC APIs for network data

Key files

FileWhy to read it
diff/diff.goDefines comparison events, paths, filtering, and callback flow
text/encoder.goShows the general purpose of readable nested-value output
text/types.goShows how special display forms represent numeric and byte values
text/tools.goShows plain string, color, and highlighting helpers
text/tree.goShows the tree-shaped inspection interface
logging.goShows the root structured logging registration
diff/logging.goShows the comparison package's logging scope and trace boundary