add scraping the torrent topics rss files

This commit is contained in:
2024-09-09 08:54:29 +03:00
parent 20c4f25c55
commit e587e645fc
26 changed files with 714 additions and 22 deletions

View File

@@ -0,0 +1,7 @@
package web
import "net/http"
func FallbackHandler(w http.ResponseWriter, r *http.Request) {
respondWithJSON(w, http.StatusOK, struct{}{})
}

35
helper/web/json.go Normal file
View File

@@ -0,0 +1,35 @@
package web
import (
"encoding/json"
"log"
"net/http"
)
type errorResponse struct {
Error string `json:"error"`
}
func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
data, err := json.Marshal(payload)
if err != nil {
log.Printf("failed to marshal JSON response: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(code)
_, err = w.Write(data)
if err != nil {
log.Printf("failed to write data to output buffer: %v\n", err)
}
}
func respondWithError(w http.ResponseWriter, code int, message string) {
if code >= http.StatusInternalServerError {
log.Println("responding with 5xx error:", message)
}
respondWithJSON(w, code, errorResponse{Error: message})
}