aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/main.go b/main.go
index 87d40fa..1b93d8d 100644
--- a/main.go
+++ b/main.go
@@ -143,7 +143,7 @@ func fetch(group string) (c *channel, err error) {
url := "https://www.facebook.com/pg/" + group + "/posts/"
- log.Println("Fetching: ", url)
+ log.Println("Fetching:", url)
resp, err := http.Get(url)
if err != nil {
@@ -162,6 +162,21 @@ func fetch(group string) (c *channel, err error) {
}
func main() {
+ // clean the cache when channels have expired
+ go func() {
+ for {
+ time.Sleep(time.Duration(cacheTimeout) * time.Second)
+ for k, c := range cache.v {
+ if time.Now().Sub(c.Time).Seconds() > cacheTimeout {
+ cache.Lock()
+ delete(cache.v, k)
+ cache.Unlock()
+ log.Println("Removed from cache:", k)
+ }
+ }
+ }
+ }()
+
log.Println("Serving: http://localhost:1212")
http.ListenAndServe(":1212", handler{})
}