-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (36 loc) · 1.11 KB
/
Copy pathmain.go
File metadata and controls
44 lines (36 loc) · 1.11 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
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
)
func main() {
http.HandleFunc("GET /_cy/ping", ping)
http.HandleFunc("POST /_cy/events", events)
http.HandleFunc("DELETE /_cy/plugin", plugin)
http.HandleFunc("POST /_cy/resync", resync)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
fmt.Printf("Server is running on port %s\n", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
func ping(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"request": "ping"})
}
func events(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"request": "events"})
}
func plugin(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"request": "plugin"})
}
func resync(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"request": "resync"})
}