go-podcast-proxy/handle-feed.go
caffeinelucy b4a978043e code
2024-08-03 20:05:08 +02:00

25 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
}