-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
42 lines (36 loc) · 847 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"log"
"net/http"
"time"
ffprobe "github.com/vansante/go-ffprobe"
)
func status(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("Ok"))
}
func handler(w http.ResponseWriter, r *http.Request) {
url := r.FormValue("url")
if url == "" {
w.WriteHeader(400)
w.Write([]byte("Url Missing"))
return
}
data, err := ffprobe.GetProbeData(url, 120000*time.Millisecond)
if err != nil {
log.Printf("Error getting data: %v", err)
w.WriteHeader(400)
w.Write([]byte("Some Error Occurred"))
return
}
duration := fmt.Sprintf("%f", data.Format.Duration().Seconds())
w.WriteHeader(200)
w.Write([]byte("{\"duration\":" + duration + "}"))
return
}
func main() {
http.HandleFunc("/", status)
http.HandleFunc("/duration", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}