forked from etix/mirrorbits
/
utils.go
108 lines (105 loc) · 3.37 KB
/
utils.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package rpc
import (
"github.com/etix/mirrorbits/mirrors"
"github.com/golang/protobuf/ptypes"
)
func MirrorToRPC(m *mirrors.Mirror) (*Mirror, error) {
stateSince, err := ptypes.TimestampProto(m.StateSince.Time)
if err != nil {
return nil, err
}
lastSync, err := ptypes.TimestampProto(m.LastSync.Time)
if err != nil {
return nil, err
}
lastSuccessfulSync, err := ptypes.TimestampProto(m.LastSuccessfulSync.Time)
if err != nil {
return nil, err
}
lastModTime, err := ptypes.TimestampProto(m.LastModTime.Time)
if err != nil {
return nil, err
}
return &Mirror{
ID: int32(m.ID),
Name: m.Name,
HttpURL: m.HttpURL,
RsyncURL: m.RsyncURL,
FtpURL: m.FtpURL,
SponsorName: m.SponsorName,
SponsorURL: m.SponsorURL,
SponsorLogoURL: m.SponsorLogoURL,
AdminName: m.AdminName,
AdminEmail: m.AdminEmail,
CustomData: m.CustomData,
ContinentOnly: m.ContinentOnly,
CountryOnly: m.CountryOnly,
ASOnly: m.ASOnly,
Score: int32(m.Score),
Latitude: m.Latitude,
Longitude: m.Longitude,
ContinentCode: m.ContinentCode,
CountryCodes: m.CountryCodes,
ExcludedCountryCodes: m.ExcludedCountryCodes,
Asnum: uint32(m.Asnum),
Comment: m.Comment,
Enabled: m.Enabled,
Up: m.Up,
ExcludeReason: m.ExcludeReason,
StateSince: stateSince,
AllowRedirects: int32(m.AllowRedirects),
LastSync: lastSync,
LastSuccessfulSync: lastSuccessfulSync,
LastModTime: lastModTime,
}, nil
}
func MirrorFromRPC(m *Mirror) (*mirrors.Mirror, error) {
stateSince, err := ptypes.Timestamp(m.StateSince)
if err != nil {
return nil, err
}
lastSync, err := ptypes.Timestamp(m.LastSync)
if err != nil {
return nil, err
}
lastSuccessfulSync, err := ptypes.Timestamp(m.LastSuccessfulSync)
if err != nil {
return nil, err
}
lastModTime, err := ptypes.Timestamp(m.LastModTime)
if err != nil {
return nil, err
}
return &mirrors.Mirror{
ID: int(m.ID),
Name: m.Name,
HttpURL: m.HttpURL,
RsyncURL: m.RsyncURL,
FtpURL: m.FtpURL,
SponsorName: m.SponsorName,
SponsorURL: m.SponsorURL,
SponsorLogoURL: m.SponsorLogoURL,
AdminName: m.AdminName,
AdminEmail: m.AdminEmail,
CustomData: m.CustomData,
ContinentOnly: m.ContinentOnly,
CountryOnly: m.CountryOnly,
ASOnly: m.ASOnly,
Score: int(m.Score),
Latitude: m.Latitude,
Longitude: m.Longitude,
ContinentCode: m.ContinentCode,
CountryCodes: m.CountryCodes,
ExcludedCountryCodes: m.ExcludedCountryCodes,
Asnum: uint(m.Asnum),
Comment: m.Comment,
Enabled: m.Enabled,
Up: m.Up,
ExcludeReason: m.ExcludeReason,
StateSince: mirrors.Time{}.FromTime(stateSince),
AllowRedirects: mirrors.Redirects(m.AllowRedirects),
LastSync: mirrors.Time{}.FromTime(lastSync),
LastSuccessfulSync: mirrors.Time{}.FromTime(lastSuccessfulSync),
LastModTime: mirrors.Time{}.FromTime(lastModTime),
}, nil
}