diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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{}) } |