Refactor with ordered maps
This commit is contained in:
@@ -44,20 +44,20 @@ type TorrentInfo struct {
|
||||
Version string `json:"-"`
|
||||
}
|
||||
|
||||
func (t *Torrent) UnmarshalJSON(data []byte) error {
|
||||
type Alias Torrent
|
||||
func (i *TorrentInfo) UnmarshalJSON(data []byte) error {
|
||||
type Alias TorrentInfo
|
||||
aux := &struct {
|
||||
Progress float64 `json:"progress"`
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(t),
|
||||
Alias: (*Alias)(i),
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &aux); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t.Progress = int(math.Round(aux.Progress))
|
||||
i.Progress = int(math.Round(aux.Progress))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user