Added handlers for Download and HLS requests.
This commit is contained in:
parent
333a51f633
commit
ff2b71b935
@ -8,23 +8,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
path := "/home/psa/GoRepository/"
|
|
||||||
port := 8080
|
port := 8080
|
||||||
|
|
||||||
http.HandleFunc("GET /download", handlers.Download) // example request: {"date": "07-03-2025", "start_time": "16-43", "end_time": "16-44"}
|
http.HandleFunc("GET /download", handlers.Download) // example request: {"date": "07-03-2025", "start_time": "16-43", "end_time": "16-44"}
|
||||||
http.HandleFunc("GET /hls", handlers.HLS)
|
http.HandleFunc("GET /hls/", handlers.HLS)
|
||||||
//http.Handle("/", addHeaders(http.FileServer(http.Dir(path))))
|
|
||||||
|
|
||||||
log.Println("Starting server on:")
|
log.Println("Starting server on:")
|
||||||
log.Printf("Serving %s on HTTP port: %d\n", path, port)
|
log.Printf("Serving on HTTP port: %d\n", port)
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//func addHeaders(h http.Handler) http.Handler {
|
|
||||||
// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
||||||
// h.ServeHTTP(w, r)
|
|
||||||
// })
|
|
||||||
//}
|
|
||||||
|
@ -7,25 +7,26 @@ import (
|
|||||||
"reader/internal/processor"
|
"reader/internal/processor"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DownloadRequest struct {
|
type VideoRequest struct {
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
StartTime string `json:"start_time"`
|
StartTime string `json:"start_time"`
|
||||||
EndTime string `json:"end_time"`
|
EndTime string `json:"end_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Download processes Download request.
|
||||||
func Download(w http.ResponseWriter, r *http.Request) {
|
func Download(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("new download request: %+v\n", r)
|
log.Printf("new download request: %+v\n", r)
|
||||||
|
|
||||||
dr := DownloadRequest{}
|
downloadRequest := VideoRequest{}
|
||||||
|
|
||||||
err := json.NewDecoder(r.Body).Decode(&dr)
|
err := json.NewDecoder(r.Body).Decode(&downloadRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("json decode error: %v\n", err)
|
log.Printf("json decode error: %v\n", err)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pathFileNameRes, err := processor.Process(dr.Date, dr.StartTime, dr.EndTime)
|
pathFileNameRes, err := processor.Process(downloadRequest.Date, downloadRequest.StartTime, downloadRequest.EndTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("process error: %v\n", err)
|
log.Printf("process error: %v\n", err)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
@ -39,7 +40,12 @@ func Download(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.ServeFile(w, r, pathFileNameRes)
|
http.ServeFile(w, r, pathFileNameRes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HLS processes Download request.
|
||||||
func HLS(w http.ResponseWriter, r *http.Request) {
|
func HLS(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("new hls request: %+v\n", r)
|
log.Printf("new hls request: %+v\n", r)
|
||||||
|
|
||||||
|
path := "/home/psa/GoRepository/data/1280x720/"
|
||||||
|
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
http.StripPrefix("/hls", http.FileServer(http.Dir(path))).ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user