From b4c73147fe80d5387003f758ebe6752f36e1f41c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 16:42:45 +0100 Subject: [PATCH] ax(node): replace direct encoding/json with package-level UnmarshalJSON wrapper worker.go imported encoding/json directly and called json.Unmarshal at two call sites. bufpool.go already provided MarshalJSON as the package wrapper; add matching UnmarshalJSON and route both worker.go call sites through it, removing the encoding/json import from worker.go. Co-Authored-By: Charon --- pkg/node/bufpool.go | 6 ++++++ pkg/node/worker.go | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/node/bufpool.go b/pkg/node/bufpool.go index 0c91dfe..7815449 100644 --- a/pkg/node/bufpool.go +++ b/pkg/node/bufpool.go @@ -29,6 +29,12 @@ func putBuffer(buffer *bytes.Buffer) { } } +// var msg Message +// if err := UnmarshalJSON(data, &msg); err != nil { return nil, err } +func UnmarshalJSON(data []byte, v interface{}) error { + return json.Unmarshal(data, v) +} + // data, err := MarshalJSON(msg) // if err != nil { return nil, err } func MarshalJSON(v interface{}) ([]byte, error) { diff --git a/pkg/node/worker.go b/pkg/node/worker.go index bb542da..b371cbe 100644 --- a/pkg/node/worker.go +++ b/pkg/node/worker.go @@ -2,7 +2,6 @@ package node import ( "encoding/base64" - "encoding/json" "fmt" "path" "time" @@ -341,7 +340,7 @@ func (worker *Worker) handleDeploy(conn *PeerConnection, msg *Message) (*Message // Unmarshal into interface{} to pass to ProfileManager var profile interface{} - if err := json.Unmarshal(profileData, &profile); err != nil { + if err := UnmarshalJSON(profileData, &profile); err != nil { return nil, fmt.Errorf("invalid profile data JSON: %w", err) } @@ -381,7 +380,7 @@ func (worker *Worker) handleDeploy(conn *PeerConnection, msg *Message) (*Message // If the bundle contained a profile config, save it if len(profileData) > 0 && worker.profileManager != nil { var profile interface{} - if err := json.Unmarshal(profileData, &profile); err != nil { + if err := UnmarshalJSON(profileData, &profile); err != nil { logging.Warn("failed to parse profile from miner bundle", logging.Fields{"error": err}) } else { if err := worker.profileManager.SaveProfile(profile); err != nil {