mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: minor code changes
This commit is contained in:
parent
d561ce1766
commit
f363135261
@ -15,7 +15,6 @@ import (
|
|||||||
"golang.org/x/sync/semaphore"
|
"golang.org/x/sync/semaphore"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const OriginWakatime = "wakatime"
|
const OriginWakatime = "wakatime"
|
||||||
@ -177,12 +176,9 @@ func (w *WakatimeHeartbeatImporter) fetchUserAgents() (map[string]*wakatime.User
|
|||||||
|
|
||||||
userAgents := make(map[string]*wakatime.UserAgentEntry)
|
userAgents := make(map[string]*wakatime.UserAgentEntry)
|
||||||
|
|
||||||
done := false
|
for page := 1; ; page++ {
|
||||||
for i:=1; !done; i++ {
|
url := fmt.Sprintf("%s%s?page=%d", config.WakatimeApiUrl, config.WakatimeApiUserAgentsUrl, page)
|
||||||
queryStr := "?page="+strconv.Itoa(i)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, config.WakatimeApiUrl+
|
|
||||||
config.WakatimeApiUserAgentsUrl+queryStr, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -196,13 +192,14 @@ func (w *WakatimeHeartbeatImporter) fetchUserAgents() (map[string]*wakatime.User
|
|||||||
if err := json.NewDecoder(res.Body).Decode(&userAgentsData); err != nil {
|
if err := json.NewDecoder(res.Body).Decode(&userAgentsData); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if i == userAgentsData.TotalPages {
|
|
||||||
done = true
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, ua := range userAgentsData.Data {
|
for _, ua := range userAgentsData.Data {
|
||||||
userAgents[ua.Id] = ua
|
userAgents[ua.Id] = ua
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if page == userAgentsData.TotalPages {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return userAgents, nil
|
return userAgents, nil
|
||||||
@ -215,12 +212,9 @@ func (w *WakatimeHeartbeatImporter) fetchMachineNames() (map[string]*wakatime.Ma
|
|||||||
|
|
||||||
machines := make(map[string]*wakatime.MachineEntry)
|
machines := make(map[string]*wakatime.MachineEntry)
|
||||||
|
|
||||||
done := false
|
for page := 1; ; page++ {
|
||||||
for i:=1; !done; i++ {
|
url := fmt.Sprintf("%s%s?page=%d", config.WakatimeApiUrl, config.WakatimeApiMachineNamesUrl, page)
|
||||||
queryStr := "?page="+strconv.Itoa(i)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, config.WakatimeApiUrl+
|
|
||||||
config.WakatimeApiMachineNamesUrl+queryStr, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -234,13 +228,14 @@ func (w *WakatimeHeartbeatImporter) fetchMachineNames() (map[string]*wakatime.Ma
|
|||||||
if err := json.NewDecoder(res.Body).Decode(&machineData); err != nil {
|
if err := json.NewDecoder(res.Body).Decode(&machineData); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if i == machineData.TotalPages {
|
|
||||||
done = true
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, ma := range machineData.Data {
|
for _, ma := range machineData.Data {
|
||||||
machines[ma.Id] = ma
|
machines[ma.Id] = ma
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if page == machineData.TotalPages {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return machines, nil
|
return machines, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user