-
Notifications
You must be signed in to change notification settings - Fork 0
/
torrent.go
39 lines (34 loc) · 944 Bytes
/
torrent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package tracker
import (
"encoding/json"
"fmt"
"time"
"github.com/gofrs/uuid"
)
type Torrent struct {
ID uuid.UUID `db:"id" json:"id"`
InfoHash []byte `db:"info_hash" json:"info_hash"`
Completed int `db:"completed" json:"completed"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
Seeders int `db:"seeders" json:"seeders"`
Leechers int `db:"leechers" json:"leechers"`
}
func (t *Torrent) MarshalJSON() ([]byte, error) {
type dto Torrent
return json.Marshal(struct {
ID string `json:"id"`
InfoHash string `json:"info_hash"`
Completed int `json:"completed"`
CreatedAt time.Time `json:"created_at"`
Seeders int `json:"seeders"`
Leechers int `json:"leechers"`
*dto
}{
ID: t.ID.String(),
InfoHash: fmt.Sprintf("%x", string(t.InfoHash)),
Completed: t.Completed,
CreatedAt: t.CreatedAt,
Seeders: t.Seeders,
Leechers: t.Leechers,
})
}