代码拉取完成,页面将自动刷新
package upnp
import (
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
)
// FROM: http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf
// Device description section, only include REQUIRED fields
type descResponse struct {
// configuration number to which the device description belongs
ConfigID string `xml:"configId,attr"`
// version templates
SpecVersion specVersionType `xml:"specVersion"`
// device object
Device deviceType `xml:"device"`
}
type specVersionType struct {
Major int `xml:"major"`
Minor int `xml:"minor"`
}
type deviceType struct {
// starts with "urn:schemas-upnp-org:device:"
DeviceType string `xml:"deviceType"`
// show name
FriendlyName string `xml:"friendlyName"`
// manufacturer name
Manufacturer string `xml:"manufacturer"`
// model name
ModelName string `xml:"modelName"`
// service list
ServiceList []serviceType `xml:"serviceList>service"`
// embedded devices
DeviceList []deviceType `xml:"deviceList>device"`
}
type serviceType struct {
// starts with "urn:schemas-upnp-org:service:"
ServiceType string `xml:"serviceType"`
// starts with "urn:upnp-org:serviceId:"
ServiceID string `xml:"serviceId"`
// url for service spec
SCPDURL string `xml:"SCPDURL"`
// url for control
ControlURL string `xml:"controlURL"`
// url for eventing
EventSubURL string `xml:"eventSubURL"`
}
func (d *Device) parse() error {
resp, err := http.Get(d.descLocation)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
data, _ := ioutil.ReadAll(resp.Body)
return fmt.Errorf("GET description info fail, http_code=%d\n%s", resp.StatusCode, string(data))
}
var desc descResponse
if err := xml.NewDecoder(resp.Body).Decode(&desc); err != nil {
return err
}
if err := d.loadService(desc.Device); err != nil {
return err
}
d.parsed = true
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。