rss image
parent
c7103d04ad
commit
1c0fc3345e
15
app.go
15
app.go
|
|
@ -25,6 +25,7 @@ type Parser interface {
|
|||
Title() string
|
||||
Description() string
|
||||
RootUrl() string
|
||||
ImageUrl() string
|
||||
ServerUrl() string
|
||||
CacheName() string
|
||||
CacheTimeout() int
|
||||
|
|
@ -65,6 +66,11 @@ func (this *ParserFeed) ParseAndUpdateCache() {
|
|||
Link: &feeds.Link{Href: this.parser.RootUrl()},
|
||||
Description: this.parser.Description(),
|
||||
Created: time.Now(),
|
||||
Image: &feeds.Image{
|
||||
Url: this.parser.ImageUrl(),
|
||||
Title: this.parser.Title(),
|
||||
Link: this.parser.RootUrl(),
|
||||
},
|
||||
}
|
||||
|
||||
entities := this.parser.Parse()
|
||||
|
|
@ -74,7 +80,7 @@ func (this *ParserFeed) ParseAndUpdateCache() {
|
|||
Id: re.url,
|
||||
Title: re.title,
|
||||
Link: &feeds.Link{Href: re.url},
|
||||
Description: re.title,
|
||||
Description: re.descripiton,
|
||||
Created: time.Now(),
|
||||
})
|
||||
}
|
||||
|
|
@ -102,13 +108,11 @@ func (this *ParserFeed) RunWorker() {
|
|||
for {
|
||||
nextmark := this.time.Add(time.Second * time.Duration(this.parser.CacheTimeout()))
|
||||
sleepfor := nextmark.Unix() - time.Now().Unix()
|
||||
fmt.Println(sleepfor)
|
||||
|
||||
if sleepfor > 0 {
|
||||
time.Sleep(time.Second * time.Duration(sleepfor))
|
||||
}
|
||||
this.ParseAndUpdateCache()
|
||||
fmt.Println("update")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,6 +156,11 @@ func main() {
|
|||
rootPage += "</body></html>"
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
w.WriteHeader(404)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, rootPage)
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue