all: statically enforce json/v2 interface satisfaction (#15154)

The json/v2 prototype is still in flux and the API can/will change.

Statically enforce that types implementing the v2 methods
satisfy the correct interface so that changes to the signature
can be statically detected by the compiler.

Updates tailscale/corp#791

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
Joe Tsai
2025-02-27 12:33:31 -08:00
committed by GitHub
parent f5522e62d1
commit 3d28aa19cb
9 changed files with 64 additions and 0 deletions

View File

@@ -147,6 +147,11 @@ type snapshotJSON struct {
Settings map[Key]RawItem `json:",omitempty"`
}
var (
_ jsonv2.MarshalerTo = (*Snapshot)(nil)
_ jsonv2.UnmarshalerFrom = (*Snapshot)(nil)
)
// MarshalJSONTo implements [jsonv2.MarshalerTo].
func (s *Snapshot) MarshalJSONTo(out *jsontext.Encoder) error {
data := &snapshotJSON{}