2021-03-16
Golang
同时定义多个相关的struct
, 这样写可读性更好一些
1type (
2 // item defines the fields associated with the item tag
3 // in the rss document.
4 item struct {
5 XMLName xml.Name `xml:"item"`
6 PubDate string `xml:"pubDate"`
7 Title string `xml:"title"`
8 Description string `xml:"description"`
9 Link string `xml:"link"`
10 GUID string `xml:"guid"`
11 GeoRssPoint string `xml:"georss:point"`
12 }
13
14 // image defines the fields associated with the image tag
15 // in the rss document.
16 image struct {
17 XMLName xml.Name `xml:"image"`
18 URL string `xml:"url"`
19 Title string `xml:"title"`
20 Link string `xml:"link"`
21 }
22
23 // channel defines the fields associated with the channel tag
24 // in the rss document.
25 channel struct {
26 XMLName xml.Name `xml:"channel"`
27 Title string `xml:"title"`
28 Description string `xml:"description"`
29 Link string `xml:"link"`
30 PubDate string `xml:"pubDate"`
31 LastBuildDate string `xml:"lastBuildDate"`
32 TTL string `xml:"ttl"`
33 Language string `xml:"language"`
34 ManagingEditor string `xml:"managingEditor"`
35 WebMaster string `xml:"webMaster"`
36 Image image `xml:"image"`
37 Item []item `xml:"item"`
38 }
39
40 // rssDocument defines the fields associated with the rss document.
41 rssDocument struct {
42 XMLName xml.Name `xml:"rss"`
43 Channel channel `xml:"channel"`
44 }
45)