go-podcast-proxy/handle-feed.go

26 lines
631 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 {
w.Header().Set("Content-Type", "application/rss+json")
fmt.Fprintf(w, e)
} else {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return nil
}
return nil
}