Refactor with ordered maps

This commit is contained in:
Ben Sarmiento
2023-11-10 19:03:07 +01:00
parent 15a0ba95d8
commit b97f859a32
12 changed files with 180 additions and 256 deletions

View File

@@ -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
}