package moved

This commit is contained in:
crusader 2018-08-29 13:08:37 +09:00
parent 0f9f14aedc
commit 01b201266c
15 changed files with 0 additions and 87 deletions

View File

@ -1,72 +0,0 @@
package ssdp
import (
"encoding/xml"
"net/http"
"github.com/koron/go-ssdp" // MIT license
)
type SpecVersion struct {
Major int `xml:"major"`
Minor int `xml:"minor"`
}
type Icon struct {
MIMEType string `xml:"mimetype"`
Width int `xml:"width"`
Height int `xml:"height"`
Depth int `xml:"depth"`
URL string `xml:"url"`
}
type Device struct {
SpecVersion SpecVersion `xml:"specVersion"`
URLBase string `xml:"URLBase"`
DeviceType string `xml:"device>deviceType"`
FriendlyName string `xml:"device>friendlyName"`
Manufacturer string `xml:"device>manufacturer"`
ManufacturerURL string `xml:"device>manufacturerURL"`
ModelDescription string `xml:"device>modelDescription"`
ModelName string `xml:"device>modelName"`
ModelNumber string `xml:"device>modelNumber"`
ModelURL string `xml:"device>modelURL"`
SerialNumber string `xml:"device>serialNumber"`
UDN string `xml:"device>UDN"`
UPC string `xml:"device>UPC"`
PresentationURL string `xml:"device>presentationURL"`
Icons []Icon `xml:"device>iconList>icon"`
}
func SearchRootDevices() ([]Device, error) {
list, err := ssdp.Search(ssdp.RootDevice, 1, "")
if err != nil {
return nil, err
}
devices := make([]Device, 0, len(list))
for _, srv := range list {
device, err := parseResponse(srv.Location)
if err != nil {
continue
}
devices = append(devices, *device)
}
return devices, nil
}
func parseResponse(url string) (*Device, error) {
response, err := http.Get(url)
if err != nil {
return nil, err
}
defer response.Body.Close()
decoder := xml.NewDecoder(response.Body)
device := &Device{}
if err := decoder.Decode(device); err != nil {
return nil, err
}
return device, nil
}

View File

@ -1,15 +0,0 @@
package ssdp
import "testing"
func TestSSDP(t *testing.T) {
devices, err := SearchRootDevices()
if err != nil {
t.Error(err)
}
for _, device := range devices {
t.Log(device)
}
}
// http://192.168.1.254:44517/etc/linuxigd/gatedesc.xml