26 lines
568 B
Go
26 lines
568 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"log"
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
func (ctx *ServerContext) HandleFeed(w http.ResponseWriter, req *http.Request) error {
|
||
|
ctx.WG.Add(1)
|
||
|
defer ctx.WG.Done()
|
||
|
name := req.URL.Path
|
||
|
name = name[len(name)-6:]
|
||
|
log.Println("requesting feed <", name, ">")
|
||
|
|
||
|
ctx.FeedCache.Lock()
|
||
|
defer ctx.FeedCache.Unlock()
|
||
|
if e, has := ctx.FeedCache.Texts[name]; has {
|
||
|
fmt.Fprintf(w, e)
|
||
|
} else {
|
||
|
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||
|
return nil
|
||
|
}
|
||
|
return nil
|
||
|
}
|