-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (51 loc) · 1.08 KB
/
main.go
File metadata and controls
59 lines (51 loc) · 1.08 KB
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
58
59
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
playpause "playpauseapi/playplause"
"github.com/gorilla/mux"
)
//Request array
type Request struct {
Command string
}
//Response
type Response struct {
Status string
}
var (
command chan string
response chan string
//runningChans = map[string]chan string
)
func init() {
}
func getParameters(w http.ResponseWriter, r *http.Request) {
var req Request
json.NewDecoder(r.Body).Decode(&req)
input := req.Command
if req.Command == "Pause" || req.Command == "Stop" {
command <- req.Command
} else {
fmt.Println("input", input)
response = make(chan string)
command = make(chan string)
// runningChans["test_name"] = command
go playpause.Routine(command, response)
}
tmp := <-response
fmt.Println(tmp)
res := Response{
Status: tmp,
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(res)
}
func main() {
fmt.Println("Server Running")
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/playPause", getParameters)
log.Fatal(http.ListenAndServe(":8000", router))
}