UnmarshalJSON unmarshals JSON to a node
(data []byte)
| 115 | |
| 116 | // UnmarshalJSON unmarshals JSON to a node |
| 117 | func (n *Node) UnmarshalJSON(data []byte) error { |
| 118 | var node struct { |
| 119 | ID string `json:"id"` |
| 120 | Name string `json:"name"` |
| 121 | IPAddress string `json:"ip_address"` |
| 122 | Port int `json:"port"` |
| 123 | CreatedAt time.Time `json:"created_at"` |
| 124 | UpdatedAt time.Time `json:"updated_at"` |
| 125 | } |
| 126 | if err := json.Unmarshal(data, &node); err != nil { |
| 127 | return err |
| 128 | } |
| 129 | n.mu.Lock() |
| 130 | defer n.mu.Unlock() |
| 131 | n.ID = node.ID |
| 132 | n.Name = node.Name |
| 133 | n.IPAddress = node.IPAddress |
| 134 | n.Port = node.Port |
| 135 | n.CreatedAt = node.CreatedAt |
| 136 | n.UpdatedAt = node.UpdatedAt |
| 137 | return nil |
| 138 | } |
| 139 | |
| 140 | // NodeService represents a node service |
| 141 | type NodeService interface { |
nothing calls this directly
no outgoing calls
no test coverage detected