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 <charon@lethean.io>
This commit is contained in:
parent
3c9ff897f2
commit
b4c73147fe
2 changed files with 8 additions and 3 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue