Make cacheEntry public so that it can be marshalled to the UI.

This commit is contained in:
Phill Luby
2014-10-15 21:52:06 +01:00
parent 36431b3dcd
commit b110b7c3f7
2 changed files with 30 additions and 25 deletions

View File

@@ -34,6 +34,7 @@ import (
"code.google.com/p/go.crypto/bcrypt"
"github.com/syncthing/syncthing/internal/auto"
"github.com/syncthing/syncthing/internal/config"
"github.com/syncthing/syncthing/internal/discover"
"github.com/syncthing/syncthing/internal/events"
"github.com/syncthing/syncthing/internal/logger"
"github.com/syncthing/syncthing/internal/model"
@@ -453,10 +454,14 @@ func restPostDiscoveryHint(w http.ResponseWriter, r *http.Request) {
func restGetDiscovery(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
registry := discoverer.All()
devices := make(map[string][]struct{}, len(registry))
for device, addrs := range registry {
devices[device.String()] = make([]struct{}, len(addrs))
// Device ids can't be marshalled as keys so we need to manually
// rebuild this map using strings.
devices := make(map[string][]discover.CacheEntry, len(registry))
for device, _ := range registry {
devices[device.String()] = registry[device]
}
json.NewEncoder(w).Encode(devices)
}