-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (43 loc) · 900 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"encoding/json"
"flag"
"log"
"net/http"
)
var (
addr = flag.String("addr", "127.0.0.1:52145", "address for http server")
help = flag.Bool("help", false, "show this")
)
func main() {
flag.Parse()
if *help {
flag.Usage()
return
}
mux := http.NewServeMux()
type data struct {
URL string
}
mux.HandleFunc("/launch", func(rw http.ResponseWriter, req *http.Request) {
switch req.Method {
case "GET":
rw.WriteHeader(http.StatusNotImplemented)
return
case "OPTIONS":
return
case "POST":
var d data
if err := json.NewDecoder(req.Body).Decode(&d); err != nil {
rw.WriteHeader(http.StatusBadRequest)
return
}
if err := launch(d.URL); err != nil {
log.Println("error:", err)
rw.WriteHeader(http.StatusInternalServerError)
}
log.Println("VLC launched:", d.URL)
}
})
http.ListenAndServe(":52145", mux)
}