Skip to content
API and data contracts

wirepolicy

Checks serialized structs and their composite literals.

AvailabilityOpt-in
Fix offeredYes

What it detects

Reports exported fields without explicit JSON or TOML tags on types that look like serialized data. It also reports positional literals for persisted or wire types when their fields should be named explicitly.

Checks

Check What it detects
keyed-literal*
Reports positional composite literals for persisted or wire structs.
serialization-tag*
Reports exported wire fields without explicit JSON or TOML tags.

* Opt-in; requires explicit selection.

Why this is flagged

Serialized data is a contract with other programs and stored data. Explicit field tags keep that contract stable when Go names change, while keyed literals keep construction correct when fields are added or reordered.

How to fix it

Add the appropriate serialization tag to every exported wire field. When constructing a wire value, name each field in the literal instead of relying on the fields’ current order.

Examples

Flagged code

Missing serialization tags

type EventRow struct {
// gohawk: serialized field ID requires an explicit json or toml tag
ID string
// gohawk: serialized field Kind requires an explicit json or toml tag
Kind string
}

Positional wire struct literal

type TaggedEventRow struct {
ID string `json:"id"`
Kind string `json:"kind"`
}
// gohawk: persisted or wire struct literal must use field keys
var event = TaggedEventRow{"42", "created"}

Accepted code

type AuditRow struct {
ID string `json:"id"`
Kind string `json:"kind"`
}
var audit = AuditRow{ID: "42", Kind: "created"}