-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXmlUPNP.go
53 lines (47 loc) · 1008 Bytes
/
XmlUPNP.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package UPnP
import (
"encoding/xml"
"io/ioutil"
"net/http"
"net/url"
)
// Icon icon info
type Icon struct {
XMLName xml.Name `xml:"icon"`
Mimetype string `xml:"mimetype"`
Width int `xml:"width"`
Height int `xml:"height"`
Depth int `xml:"depth"`
URL string `xml:"url"`
}
// Root root description file
type Root struct {
XMLName xml.Name `xml:"root"`
Location *url.URL
Device *Device `xml:"device"`
}
// NewXMLUPNPFile get description file
func NewXMLUPNPFile(_url string) (*Root, error) {
rep, err := http.Get(_url)
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(rep.Body)
r := Root{}
err = xml.Unmarshal(bytes, &r)
if err != nil {
return nil, err
}
r.Location, _ = url.Parse(_url)
return &r, nil
}
// GetDevice return child device
func (r *Root) GetDevice() *Device {
device := r.Device
device.upnpRoot = r
return device
}
// GetLocation return location url
func (r *Root) GetLocation() *url.URL {
return r.Location
}