mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
Don't crash on nil discoverer (fixes #917)
This commit is contained in:
parent
048883ad27
commit
6820c0a5d7
@ -453,13 +453,15 @@ func restPostDiscoveryHint(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func restGetDiscovery(w http.ResponseWriter, r *http.Request) {
|
func restGetDiscovery(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
registry := discoverer.All()
|
devices := map[string][]discover.CacheEntry{}
|
||||||
|
|
||||||
|
if discoverer != nil {
|
||||||
// Device ids can't be marshalled as keys so we need to manually
|
// Device ids can't be marshalled as keys so we need to manually
|
||||||
// rebuild this map using strings.
|
// rebuild this map using strings. Discoverer may be nil if discovery
|
||||||
devices := make(map[string][]discover.CacheEntry, len(registry))
|
// has not started yet.
|
||||||
for device, _ := range registry {
|
for device, entries := range discoverer.All() {
|
||||||
devices[device.String()] = registry[device]
|
devices[device.String()] = entries
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(devices)
|
json.NewEncoder(w).Encode(devices)
|
||||||
|
Loading…
Reference in New Issue
Block a user